Reputation: 216
I have some data, and I want to plot confidence interval using ggplot
's 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:
Upvotes: 1
Views: 385
Reputation: 39613
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()
. 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:
#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:
Upvotes: 1