[英]Adding space between bars in ggplot2
我想在 ggplot2 中的条之间添加空格。 此页面提供了一种解决方案: http : //www.streamreader.org/stats/questions/6204/how-to-increase-the-space-between-the-bars-in-a-bar-plot-in-ggplot2 。 然而,该解决方案不是对 x 轴分组使用因子水平,而是创建一个数字序列 x.seq,以手动放置条形,然后使用width()
参数缩放它们。 但是,当我对 x 轴使用因子级别分组时, width()
不起作用,如下例所示。
library(ggplot2)
Treatment <- rep(c('T','C'),each=2)
Gender <- rep(c('M','F'),2)
Response <- sample(1:100,4)
df <- data.frame(Treatment, Gender, Response)
hist <- ggplot(df, aes(x=Gender, y=Response, fill=Treatment, stat="identity"))
hist + geom_bar(position = "dodge") + scale_y_continuous(limits = c(0,
100), name = "")
有谁知道如何获得与链接示例相同的效果,但同时使用因子级别分组?
这是你想要的吗?
hist + geom_bar(width=0.4, position = position_dodge(width=0.5))
width
在geom_bar
确定条的宽度。position_dodge
width
决定了每个条的位置。和他们一起玩一段时间后,你可能很容易理解他们的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.