[R] Howto overlay two plots and save them in one pdf file?
Andy Bunn
abunn at whrc.org
Thu Apr 21 19:29:25 CEST 2005
> > Do you mean a second y axis? If so then something like this would
> > do it
>
> Not exactly, I would also take advantage of overlaying the fitting
> curve of LAD on OLS, since both rely on the same dataset. Maybe two
> regression lines with varying shapes (i.E. straight versus dotted
> line)
Like this?
library(quantreg)
Age <- rnorm(50)
SBP <- Age * runif(50)
pdf("junk.pdf")
# plot the data
plot (Age, SBP, ylab = "SBP")
# LAD regression and related line
abline(rq(formula = SBP ~ Age), col = "red")
# OLS regression and related line
abline(lm(SBP ~ Age), col = "blue", lty = "dotted")
# make a legend
legend(-2,1, c("LAD", "LM"), col = c("red", "blue"), text.col= c("red",
"blue"), lty = c("solid", "dotted"))
dev.off()
HTH, Andy
More information about the R-help
mailing list