【问题标题】:facets as in facet_grid, and axis.line as for facet_wrap?facet_grid 中的 facets 和 facet_wrap 中的axis.line?
【发布时间】:2020-03-15 15:04:05
【问题描述】:

我正在尝试使用 中的构面构建绘图,因此使用两个因子在 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))

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

不会出现此问题,但此函数显然不会对两个轴中的因子进行分组,或者条带将始终位于一侧(根据 strip.position 参数),但不会向上和至于facet_grid。例如:

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))

问题 是否可以使用facet_grid 创建绘图,但在所有轴上都有线,或者使用facet_wrap,但使用facet_grid 分组因素?

【问题讨论】:

  • 你能添加一些视觉例子/情节吗?也许这对某些人会有帮助。

标签: facet-grid facet-wrap r ggplot2 facet-wrap facet-grid


【解决方案1】:

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

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))

【讨论】:

    猜你喜欢
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 2022-09-29
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多