-1

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!

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.

  • 2
    Can you share a sample of your data by using `dput(your_data)` ? – shafee Jul 09 '22 at 18:49
  • My data look like this: Column A: depth, column B: temperature. There are 13 profiles like this, so there are always several data poitns per 1-meter-depth-bin. – Chris A. Ora Jul 09 '22 at 19:14

1 Answers1

0

Try geom_smooth(method = "loess"):

ggplot(cars, aes(speed, dist)) +
  geom_point() + 
  geom_smooth(method = "loess")
  • This was also my first attempt, but the loess function overfits the data distribution. – Chris A. Ora Jul 09 '22 at 22:43
  • Could you post how the "loess" chart looks like? Is your question about visualization or modeling? I ask you that because I had considered your issue just as a graphic replacement problem. – Danusio Gadelha Filho Jul 10 '22 at 18:27