0

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:

plot shown using the ggplot code

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • 2
    Hi, thanks for your question! We would like to help you, but can you present a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? If you have a dataset, you can paste in your question the result of `dput(your.data.frame)` (or a sample of it if very large via `dput(your.df[sample(nrow(your.df), num),]`. Also, can you post the entire code you are using for your plot? Finally: by "not plot anything" does that mean you get entirely blank (white) or do you get the plot area, but no geoms? – chemdork123 Apr 21 '20 at 15:30
  • Hello! I have tried to present a reproducible example, I got all the other geoms plotted and it shows, while the ```geom="ribbon"``` does not show on the plot. – jinahyejin Apr 21 '20 at 15:41
  • Hi @jinahyejin, reproducible implies if I take the code above, I can say make the same plot as you have soon. That way, we can know where the error has occur, or how to help you with your issue – StupidWolf Apr 21 '20 at 17:59
  • Looking at what you have, if the predicted values are from a model (for example gam); you should be able to get a standard error of the prediction from it. You should use that to plot your c.i. Again this information is lacking – StupidWolf Apr 21 '20 at 18:05

1 Answers1

0

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()
Tim Assal
  • 677
  • 6
  • 15