I am trying to use stat_smooth()
to draw the confidence interval around a fitted line, e.g.:
Days <- c(rep(0,2),rep(10,4))
Resp <- c(1020, 955, 1599, 1220, 1264, 1273)
DummySet <- as.data.frame(cbind(Days,Resp))
a <- ggplot(data=DummySet, aes(Days, Resp))
a <- a + stat_smooth(method="lm", formula = y ~ x)
a
That's fine, but I face 2 problems when limiting the range of the y-axis. First, the CI shading is interrupted (instead of truncated) at the y-limit:
a <- a + ylim(c(800,1600))
Second, if some points are outside of the y-range, they seem to be ignored for calculations (here 1599 seems to be ignored):
a <- a + ylim(c(800,1400))
Instead, what I would like to see is the same as in the first graphic, only with truncated CI:
The problem may not be related to stat_smooth() but to a general misunderstanding of ggplot2, to which I am a newbie. Any hint would be appreciated.
No comments:
Post a Comment