简体   繁体   English

R ggplot:置信区间图

[英]R ggplot: confidence interval plot

I have some data , and I want to plot confidence interval using ggplot 's stat_summary .我有一些数据,我想使用ggplotstat_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:所以我的问题是:

  1. How can I change names of "shop" columns?如何更改“商店”列的名称?
  2. How can I change length of summary lines?如何更改摘要行的长度?
  3. How can I set distance between two datalines in one column?如何设置一列中两条数据线之间的距离?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM