R ggplot:置信区间图

时间:2020-10-22 17:12:59

标签: r ggplot2

我有一些data,并且我想使用ggplot的{​​{1}}来绘制置信区间。

我的代码如下:

stat_summary

enter image description here

但是我想得到这样的东西:

enter image description here

所以我的问题是:

  1. 如何更改“商店”列的名称?
  2. 如何更改摘要行的长度?
  3. 如何在一列中设置两条数据线之间的距离?

1 个答案:

答案 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'))

输出:

enter image description here

对于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))

输出:

enter image description here

相关问题