【问题标题】:Grid of plots in ggplotggplot中的图网格
【发布时间】:2016-03-01 12:24:02
【问题描述】:

我需要为 213 x 4 的数据框显示图表网格。 当我在 ggplot2 中使用以下命令时,该图是一个很长的线性显示图,这些图被揉成一团

 ggplot(data=r,aes(x=wicketPlayerOut,y=runs,fill=wicketPlayerOut)) + 
    facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
    geom_bar(stat="identity") + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1))

我尝试使用 facet_wrap 但出现错误

"layout_base 中的错误(data, vars, drop = drop) : 至少一层必须包含用于分面的所有变量"

我用于facet_wrap的命令如下

   ggplot(data=r,aes(x=wicketPlayerOut,y=runs,fill=wicketPlayerOut)) + 
    facet_wrap(. ~ bowler,scales = "fixed",ncol=4,drop=TRUE)+
    geom_bar(stat="identity") + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1))

如何按图列显示为 A x B 行?

【问题讨论】:

  • facet_wrap中的公式改为~ bowler
  • 罗兰-谢谢。我刚刚做了,它奏效了。你可以回答这个问题,我会接受。

标签: r ggplot2 facet-wrap


【解决方案1】:

改为如下

ggplot(data=r,aes(x=wicketPlayerOut,y=runs,fill=wicketPlayerOut)) + 
facet_wrap( ~ bowler,scales = "fixed",ncol=4,drop=TRUE)+
geom_bar(stat="identity") + 
theme(axis.text.x = element_text(angle = 90, hjust = 1))

现在显示为 nrow x ncol

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多