【问题标题】:ggplot- change space between bars [duplicate]ggplot-改变条之间的空间[重复]
【发布时间】:2018-04-18 14:03:22
【问题描述】:

我确信它是一个基本的,但即使经过广泛的搜索也找不到。

No  Status  Val Duration
I1  IS      New 1
I1  IS      InP 2
I1  IS      Re  3
I1  IS      Clo 4
I2  IS      New 20
I2  IS      InP 50
I2  IS      Re  20
I2  IS      Clo 5
I3  IS      New 3
I3  IS      Inp 8
I3  IS      Re  2
I3  IS      Clo 6 

ggplot(df,aes(x = No, y = Duration,fill=Val)) + 
geom_bar(position = position_fill(),stat = "identity",width=0.09) +
  scale_y_continuous(labels = percent_format())

如何减少我使用的条之间的间距以避开它的取消堆叠和并排设置

【问题讨论】:

  • 忽略现有答案中关于coord_flip 和面板边框的部分。在您的情况下,尝试宽度和纵横比。例如ggplot(df, aes(No, Duration)) + geom_col(aes(fill = Val), width = 0.5) + theme(aspect.ratio = 4).
  • @neilws ,aspect.ratio 将改变图像的比例。
  • @RanaUsman 是的。但我没有看到另一种方法来减少空白,同时保持更细的条形。
  • 还有其他方法可以实现相同的、更细的条形且间距很小吗?
  • 我想我是通过调整宽度和纵横比来实现的。唯一的缺点是我不能有动态图表。但现在我的记录有限,所以现在可以使用。感谢 neilfws 和 RanaUsman

标签: r ggplot2 spacing


【解决方案1】:

调整宽度。

    ggplot(df,aes(x = No, y = Duration,fill=Val)) +  
    geom_bar(position = position_fill(),stat = "identity") 

如您所见,在这种情况下,我从您的原始代码中删除了 width 参数。

结果

【讨论】:

  • 谢谢!我所需要的只是一个彼此靠近的细条。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多