How about something like this?
x <- 1:10
dd <- data.frame(x = x, y = 0.8 + 0.5 * x + rnorm(10, s = 1.5))
m <- lm(y ~ x, data = dd)
pp <- data.frame(x = x, predict(m, interval = 'confidence')
g <- ggplot(dd, aes(x = x, y = y)) + geom_point(size = 2.5) +
geom_smooth(method = 'lm', size = 1, se = FALSE)
g + geom_smooth(data = pp, aes(y = lwr), color = 'dodgerblue') +
geom_smooth(data = pp, aes(y = upr), color = 'dodgerblue')
HTH,
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
x <- 1:10
dd <- data.frame(x = x, y = 0.8 + 0.5 * x + rnorm(10, s = 1.5))
ggplot(dd, aes(x = x, y = y)) + geom_point() + stat_smooth(method = "lm", se = FALSE) + stat_smooth(method = "lm", colour = "red", geom = "ribbon", fill = NA)
#some tweaking to get rid to the vertical lines of the ribbon. The trick: expand the range with scale() then zoom in with coord()
ggplot(dd, aes(x = x, y = y)) + geom_point() + stat_smooth(method = "lm", se = FALSE) + stat_smooth(method = "lm", colour = "red", geom = "ribbon", fill = NA, fullrange = TRUE) + scale_x_continuous(limits = diff(range(dd$x)) * c(-0.2, 0.2) + range(dd$x)) + coord_cartesian(xlim = range(pretty(dd$x)))
Best regards,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry....@inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
> -----Oorspronkelijk bericht-----
> Van: ggp...@googlegroups.com
> [mailto:ggp...@googlegroups.com] Namens Ben
> Verzonden: dinsdag 3 mei 2011 14:36
> Aan: ggplot2
> Onderwerp: Re: Plot 95%CI with lines, not shading ()
> > > + =