简体   繁体   English

在ggplot上绘制均值的置信区间

[英]Plotting confidence interval of the means on ggplot

I have 10 different trials (with each their own data set).我有 10 个不同的试验(每个试验都有自己的数据集)。 I have already found the predicted values that was taken from model and created a new column with the prediction values.我已经找到了取自 model 的预测值,并使用预测值创建了一个新列。

I bounded all the x, y, and the predicted.y values for each trial into one dataframe by rbind()我通过rbind()将每个试验的所有 x、y 和 predict.y 值限制为一个 dataframe

I want to plot the mean of all the y values with the same x values (of the predicted values) and also plot the confidence interval using the geom_ribbon rather than the error bars.我想 plot 具有相同 x 值(预测值)的所有 y 值的平均值以及 plot 使用 geom_ribbon 而不是误差线的置信区间。

I have already referred to this link: plotting the means with confidence intervals with ggplot , however, when I plot the stat_summary(geom="ribbon", fun.data=mean_cl_normal, fun.args=list(conf.int=0.95), fill="lightblue") the ggplot does not plot anything but it also does not come out with any errors so I'm not sure what went wrong.我已经提到了这个链接: 用 ggplot 绘制带有置信区间的平均值,但是,当我 plot 时, stat_summary(geom="ribbon", fun.data=mean_cl_normal, fun.args=list(conf.int=0.95), fill="lightblue") ggplot 没有 plot 任何东西,但它也没有出现任何错误,所以我不确定出了什么问题。

Is there another way to have the same result with different code?是否有另一种方法可以使用不同的代码获得相同的结果? Or is there a problem with the way I bounded my values and dataset?还是我限制值和数据集的方式有问题?

MORE INFO更多信息

This is the combined data这是合并的数据

y<dbl> x<dbl> predy<dbl>
0.300   83.69   0.3292044030        
0.312   83.69   0.3291121879        
0.324   83.69   0.3291012056        
0.330   83.69   0.3287549029        
0.330   83.61   0.3291187262        
0.335   83.57   0.3293862893        
0.334   83.36   0.3303592465        
0.329   82.79   0.3328754639        
0.324   82.55   0.3339801283        
0.323   82.92   0.3319657277        

When I used the code:当我使用代码时:

 ggplot(ASframe, aes(x=x, y=y))+
 stat_summary(geom="ribbon", fun.data=mean_cl_normal, fun.args=list(conf.int=0.95), fill="lightblue")+
  stat_summary(geom = "line", fun = mean, linetype = "dashed")+
  stat_summary(geom = "point", fun=mean, color= "red", alpha = I(0.5)) +
  ylim(-0.1, 0.6)

The results came out to be:结果是:

使用 ggplot 代码显示的图

Welcome to SO.欢迎来到 SO。 It's difficult to answer the question without a reproducible example https://stackoverflow.com/help/minimal-reproducible-example .如果没有可重现的示例https://stackoverflow.com/help/minimal-reproducible-example ,很难回答这个问题。 I would try the geom_smooth option.我会尝试 geom_smooth 选项。 Here is a reproducible example using geom_smooth to plot the confidence interval that will hopefully get you started.这是一个使用 geom_smooth 到 plot 的可重现示例,置信区间有望帮助您入门。

#plot for sepal length and petal length of setosa species
 ggplot(subset(iris, iris$Species=="setosa"),aes(Sepal.Length,Petal.Length))+
    geom_point(position="jitter")+
    geom_smooth()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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