[英]R ggplot: confidence interval plot
I have some data , and I want to plot confidence interval using ggplot
's stat_summary
.我有一些数据,我想使用
ggplot
的stat_summary
绘制置信区间。
My code looks like this:我的代码如下所示:
file <- read.csv(filepath)
ggplot(file, aes(shop, income, colour = season)) + stat_summary(size = 0.8)
But I want to get something like this:但我想得到这样的东西:
So my questions are:所以我的问题是:
Try this approach.试试这个方法。 The size of the bars depends on how intervals are being computed.
条形的大小取决于间隔的计算方式。 For the other points you can use
position_dodge()
and scale_x_discrete()
.对于其他点,您可以使用
position_dodge()
和scale_x_discrete()
。 Here the code:这里的代码:
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'))
Output:输出:
For y-axis, try this:对于 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))
Output:输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.