我有一些data,并且我想使用ggplot
的{{1}}来绘制置信区间。
我的代码如下:
stat_summary
但是我想得到这样的东西:
所以我的问题是:
答案 0 :(得分:1)
尝试这种方法。条形图的大小取决于间隔的计算方式。对于其他几点,您可以使用position_dodge()
和scale_x_discrete()
。这里的代码:
library(ggplot2)
#Code
file <- read.csv('sales.csv')
#Plot
ggplot(file, aes(shop, income, colour = season)) +
stat_summary(size = 0.8,position = position_dodge(0.25))+
scale_x_discrete(limits=c("Shop â„–1","Shop â„–2"),
labels=c('Shop1','Shop2'))
输出:
对于y轴,请尝试以下操作:
#Plot 2
ggplot(file, aes(shop, income, colour = season)) +
stat_summary(size = 0.8,position = position_dodge(0.25))+
scale_x_discrete(limits=c("Shop â„–1","Shop â„–2"),
labels=c('Shop1','Shop2'))+
scale_y_continuous(breaks = c(1050,1100,1150))
输出: