如facet_grid中的方面,和axis.line如facet_wrap中?

我正在尝试像中那样使用构面来构建图,因此使用两个因子在x和y轴上分别绘制图,例如:

mtcars %>% ggplot() +
  geom_point(aes(x=mpg,y=wt)) + 
  facet_grid(cyl ~ gear,scales="free") + 
  theme(panel.background = element_blank(),axis.line = element_line(size=0.5))

如facet_grid中的方面,和axis.line如facet_wrap中?

上述方法的问题在于,最上方和最左侧的图仅显示了轴线,因此不使用彩色panel.background很难区分图。

不会发生此问题,但是此函数显然不会在两个轴上分组因子,或者,条带将始终位于侧面之一(根据strip.position自变量),但facet_grid却不正确。例如:

mtcars %>% ggplot() + 
  geom_point(aes(x=mpg,y=wt)) +
  facet_wrap(cyl ~ gear,axis.line = element_line(size=0.5))

如facet_grid中的方面,和axis.line如facet_wrap中?

问题 可以使用facet_grid但在所有轴上都是线来创建图,还是可以使用facet_wrap但可以像facet_grid那样使用组因子?

guomaochh 回答:如facet_grid中的方面,和axis.line如facet_wrap中?

我认为您正在facet_rep_grid包中寻找lemon。这是生成所需图的代码。

library(tidyverse)
library(lemon)

mtcars %>% ggplot() + 
  geom_point(aes(x=mpg,y=wt)) + 
  facet_rep_grid(cyl ~ gear,scales="free",repeat.tick.labels = "all") + 
  theme(panel.background = element_blank(),axis.line = element_line(size=0.5))

Plot lemon rep

本文链接:https://www.f2er.com/2643130.html

大家都在问