【问题标题】:facet_wrap with different factor levels in each subplot在每个子图中具有不同因子水平的 facet_wrap
【发布时间】:2017-06-28 10:37:50
【问题描述】:

是否有可能使用facet_wrap 从第一个子图中删除“fe d”级别并从第二个子图中删除“c b a”?换句话说,我希望在第一个子图上只有“c b a”列,在第二个子图中只有“f e d”列。

示例数据帧:

df <- data.frame(x = letters[1:6], gr = c(rep("kk", 3), rep("yy", 3)), v = 10:15) 

绘图调用:

ggplot(data = df, aes(x = x, y = v)) +
  geom_col() +
  coord_flip() +
  facet_wrap(~gr, nrow = 2)

【问题讨论】:

    标签: r ggplot2 facet-wrap


    【解决方案1】:

    要避免 y 轴的固定比例,只需将 scales = "free_y" 添加到 facet_wrap() 命令即可。

    ggplot(data = df, aes(x = x, y = v)) +
      geom_col() +
      coord_flip() +
      facet_wrap(~gr, nrow = 2, scales = "free_y")
    

    【讨论】:

    • 非常感谢。以前没有考虑过在这种情况下使用“free_y”选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 2017-04-04
    • 2020-11-13
    • 1970-01-01
    • 2021-04-15
    • 2015-12-22
    • 1970-01-01
    相关资源
    最近更新 更多