[英]facets as in facet_grid, and axis.line as for facet_wrap?
I am trying to build a plot using facets as in facet-grid , so plots separate in the x and y axes using two factors, as with:我正在尝试使用 facets 构建一个绘图,如facet-grid ,因此使用两个因素在 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))
The problem with the above approach is that only axis lines are shown for the up and left-most plots, so it is difficult to differentiate plots without using a colored panel.background
.上述方法的问题是只显示了最上图和最左图的轴线,因此在不使用彩色panel.background
情况下很难区分图。
This problem does not occur with facet-wrap , but this function will apparently not group factors in the two axes, or the strips will be always in one of the sides (according to strip.position
argument), but not up and right as for facet_grid
. facet-wrap不会出现此问题,但此函数显然不会对两个轴中的因素进行分组,或者条带将始终位于一侧(根据strip.position
参数),但不会向上和向右facet_grid
。 eg:例如:
mtcars %>% ggplot() +
geom_point(aes(x=mpg, y=wt)) +
facet_wrap(cyl ~ gear, scales="free") +
theme(panel.background = element_blank(), axis.line = element_line(size=0.5))
Question Is it possible to create a plot with facet_grid
, but lines in all axes, or alternatively use facet_wrap
, but group factors as with facet_grid
?问题是否可以使用facet_grid
创建绘图,但在所有轴上都有线条,或者使用facet_wrap
,但与facet_grid
一样对因子进行facet_grid
?
I think you are looking for facet_rep_grid
in the lemon
package.我认为您正在lemon
包中寻找facet_rep_grid
。 Here is the code to produce the desired plot.这是生成所需图的代码。
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.