Home > Software design >  Mean line with 95% confidence intervall for vertical depth profile
Mean line with 95% confidence intervall for vertical depth profile

Time:07-11

I want to plot temperature data measured from the surface down to 500 m depth. Currently, I have a scatterplot, but wish to substitute the dotts with a mean line and a 95% confidence band. So far, there is no magic behind this plot, i.e., ordinary code for a scatterplot.

Can anybody suggest a solution and some sample R code for replacing the scatter by a line with confidence bands? Binning the data per meter-interval may be a first step

enter image description here

This is an example of how the final plot could look like: enter image description here

Thanks, appreciate your support!

CodePudding user response:

Try geom_smooth(method = "loess"):

ggplot(cars, aes(speed, dist))  
  geom_point()   
  geom_smooth(method = "loess")

CodePudding user response:

Obviously, I am not allowed yet to post plots in replies and comments. Will need to describe it then. The loess function represents the data cloud not well as it overfits in the top 100 m, does not follow the near constant temperature in the uppermost 30 meters. I am looking for some code that bins the data per meter and then calculates mean and standard deviation that are used in the second part of the code to create mean line and confidence bands.

  • Related