Question

I have a series of values with a mean and a 2sd error:

structure(list(Site = 1:5, Value = c(0.54, 0.36, 0.13, 0.25, 
0.05), Error = c(0.26, 0.27, 0.25, 0.4, 0.24)), .Names = c("Site", 
"Value", "Error"), class = "data.frame", row.names = c(NA, -5L
))

I am trying to represent this a series of normal curves on one graph where the mid point of the curve is the mean and the range of the base of the curve is the mean+error/mean-error. The height of the curves can all be the same as we give each mean value the same weight.

I've had a search and I am really stuck. Sorry if I am missing somewhere where this may have been answered.

Was it helpful?

Solution

First you need to set up the plot but give 'plot' an NA to suppress any plotting. When you do that, plot requires ranges for X and Y

plot(NA, xlim=c( min(dat$Value)-max(dat$Error), 
                 max(dat$Value)+max(dat$Error) ),
         ylim=c(0,1) )
apply(dat, 1, function(x){ xx <-seq( x['Value']-x['Error'], 
                                    x['Value']+x['Error'], length=20);
                           yy=dnorm(xx, x['Value'], x['Error']/2);  sd is 1/2 'Error'
                           lines(xx,  yy/max(yy)) })  # normalize to peak == 1

If you want a smoother plot near the means, you can always increase the length of the 'xx' sequence.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top