![](/img/trans.png)
[英]How to reduce the spacing between bars without increasing their width in a geom_bar plot made with ggplot2?
[英]ggplot2 : How to reduce the width AND the space between bars with geom_bar
我知道可以使用width
参数更改geom_bar
中条的width
。 确实可以,但是随后会在条之间产生更大的间隙。 有没有办法手动将拉杆推得更近些? 我应该以某种方式操纵轴吗?
这是一个示例,将右侧的宽度更改为0.3,以获得所需的条形宽度。
library(tidyverse)
library(gridExtra)
p1 <- ggplot(iris, aes(Species, Petal.Length)) + geom_bar(stat="summary")
p2 <- ggplot(iris, aes(Species, Petal.Length)) + geom_bar(stat="summary", width=0.3)
grid.arrange(p1,p2,nrow=1)
注意:我知道这个问题与此类似,但是缩小差距的答案并不明显。
与其将宽度变小而不是使宽度变窄,而是增加了条间的间距,不如将宽度设置width = 1
来消除之间的所有width = 1
。*
ggplot(iris, aes(Species, Petal.Length, fill=Species)) + geom_bar(stat="summary", width=1)
默认值为0.9,因此通过设置width = 0.95
可以获得很小的空间
ggplot(iris, aes(Species, Petal.Length, fill=Species)) + geom_bar(stat="summary", width=0.95)
fill=Species
,我自由添加了颜色,以在它们之间没有空格时帮助查看不同的条。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.