亲爱的,我想在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)
有没有人知道如何获得与链接示例中相同的效果,但在使用因子级别分组时?
干杯,
亚伦
我想使用ggplot2
和来设计冲积图中各组之间的距离ggalluvial
我的示例来自https://corybrunson.github.io/ggalluvial/articles/ggalluvial.html
data(vaccinations)
levels(vaccinations$response) <- rev(levels(vaccinations$response))
ggplot(vaccinations,
aes(x = survey, stratum = response, alluvium = subject,
y = freq,
fill = response, label = response)) +
scale_x_discrete(expand = c(.1, .1)) +
geom_flow() +
geom_stratum(alpha = .5) +
geom_text(stat = "stratum", size = 3) +
theme(legend.position = "none") +
ggtitle("vaccination survey responses at three points in time")
Run Code Online (Sandbox Code Playgroud)
给我:
现在,我想缩短ms153_NSA之间的距离,同时保持ms432_NSA和ms460_NSA之间的距离相同:
我尝试使用以下命令(未成功):
https://rdrr.io/cran/ggalluvial/man/stat_flow.html
甚至谷歌也没有给我显示不对称的冲积图::'-/
我有一个条形图:
p <- ggplot(data=df, aes(x=Gene, y=FC, fill=expt, group=expt))
p <- p + geom_bar(colour="black", stat="identity", position = position_dodge(width = 0.9))
p <- p + geom_errorbar(aes(ymax = FC + se, ymin = FC, group=expt),
position = position_dodge(width = 0.9), width = 0.25)
p
Run Code Online (Sandbox Code Playgroud)
我想增加条之间的间距(对于每个bin).我已经尝试过乱搞position_dodge(width = ...)
但是它会使我的误差条偏斜:
还有其他一些与此相关的问题:
即它似乎增加了箱之间,但代价是与相邻的酒吧重叠
ggplot(scount_all, aes(x=classes, y=frequency, group=seasons,fill=seasons)) +
scale_fill_manual(name = "Seasons",values=bwPalette(4))+
geom_bar(colour="black",stat="identity", position="dodge")+
geom_text(aes(ymax=frequency,label = paste(sprintf("%s", frequency)),
hjust= 0.5,vjust=-2,group=seasons),
size = 2, position = position_dodge(width=.9)) +
theme_bw()+
theme(legend.key = element_rect(colour = "black")) +
guides(fill = guide_legend(override.aes = list(colour = NULL)))
Run Code Online (Sandbox Code Playgroud)
这是我得到的数字
正如您所看到的,一些数字是重叠的,而另一些数字则不可见。如何稍微增加条形的宽度以使数字可见?五位数是我数据中最大的数字。