【问题标题】:How to switch facet_grid to facet_wrap如何将 facet_grid 切换到 facet_wrap
【发布时间】:2022-09-29 18:05:20
【问题描述】:

上下文:我正在尝试将 facet_grid 转换为 facet_wrap 以添加 ncols。我知道 cols=conference 会改变,但我不确定如何改变。

graph <- ggplot(data, aes(week, positivity_rate, color=school)) + 
geom_line() +
facet_grid(cols=vars(conference)) 
graph
  • 您能否使用dput 分享一些可重现的数据?
  • 在 R 控制台中使用 ?facet_wrap 将显示帮助页面,并且应该为您提供很好的(且可重现的)示例。我们可以从那里帮助您。
  • 基于使用 ?facet_wrap 似乎我需要定义列等于会议并设置 ncol=2。我不确定如何将列定义为会议。
  • facet_wrap 没有 cols 参数。使用facet_wrap(vars(conference), ncol = 2)facet_wrap(facets = vars(conference), ncol = 2)facet_wrap(~conference, ncol = 2)

标签: r ggplot2 facet-wrap


【解决方案1】:
library(tidyverse)

ggplot(iris, aes(Petal.Length, Petal.Width, color=Species)) + 
  geom_line() +
  facet_grid(cols=vars(Species)) 

ggplot(iris, aes(Petal.Length, Petal.Width, color=Species)) + 
  geom_line() +
  facet_wrap(~Species,ncol = 2) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    相关资源
    最近更新 更多