亲爱的,我想在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 = "")
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何获得与链接示例中相同的效果,但在使用因子级别分组时?
干杯,
亚伦
koh*_*ske 77
这是你想要的吗?
hist + geom_bar(width=0.4, position = position_dodge(width=0.5))
Run Code Online (Sandbox Code Playgroud)
width
in geom_bar
确定条的宽度.width
in position_dodge
确定每个柱的位置.在玩了一段时间之后,你可能很容易理解他们的行为.
归档时间: |
|
查看次数: |
52703 次 |
最近记录: |