Reputation: 2861
Using ggplot2 is there anyway that confidence band or something that resembles a confidence band can be generated using the minimum and maximum values surrounding a mean value in geom_line
plot?
Data:
Year Value Group
50 0.25 Avg
100 0.30 Avg
200 0.27 Avg
250 0.26 Avg
500 0.22 Avg
1000 0.24 Avg
5000 0.27 Avg
10000 0.23 Avg
50 0.24 Max
100 0.29 Max
200 0.24 Max
250 0.23 Max
500 0.20 Max
1000 0.22 Max
5000 0.22 Max
10000 0.20 Max
50 0.28 Min
100 0.33 Min
200 0.31 Min
250 0.30 Min
500 0.27 Min
1000 0.26 Min
5000 0.32 Min
10000 0.33 Min
Current plot looks like this:
But would like the max and min lines to look like a confidence band!
I also have the underlying data used to produce the above if that is required, any hints or ideas would be very much welcomed.
Upvotes: 4
Views: 1170
Reputation: 21507
require(reshape2)
dat_cast <- dcast(dat, Year~Group, value.var = "Value")
ggplot(dat_cast, aes(x=Year, y=Avg)) +
geom_ribbon(aes(ymin = Min, ymax = Max), alpha = 0.5) +
geom_line(col = 2)
Upvotes: 7