简体   繁体   中英

Plotting confidence interval of the means on ggplot

I have 10 different trials (with each their own data set). I have already found the predicted values that was taken from model and created a new column with the prediction values.

I bounded all the x, y, and the predicted.y values for each trial into one dataframe by rbind()

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.

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.

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. It's difficult to answer the question without a reproducible example https://stackoverflow.com/help/minimal-reproducible-example . I would try the geom_smooth option. Here is a reproducible example using geom_smooth to plot the confidence interval that will hopefully get you started.

#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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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