Revision 3 as of 2009-02-10 22:09:44

Clear message

How to use R to determine unknowns on an XY plot

x <- c(2.2,2.45,2.75,3.1,3.65)
y <- c(500,400,300,200,100)


mdata <- data.frame(x=x, y=log10(y))
my.fit <- lm(y ~ x, data=mdata)


unk <- data.frame(x=c(2.9, 3.3))
predict.lm(my.fit, unk, se.fit=T)

png(filename="mobility_plot.png", width=500, height=500)
plot(x, log10(y), pch=19, main="size vs. mobility", xlab="cm", ylab="size (bp)", yaxt="n")
abline(my.fit, col="grey")
# 2.381945 2.188279
segments(0, 2.38, 2.9, 2.38, lty="dashed", col="grey")
segments(0, 2.188, 3.3, 2.188, lty="dashed", col="grey")

segments(2.9, min(log10(y)), 2.9, 2.38, lty="dashed", col="grey")
segments(3.3, min(log10(y)), 3.3, 2.188, lty="dashed", col="grey")


axis(2, at = log10(y), labels = y)
text(2.25, 2.36, "241 bp", col="grey30")
text(2.25, 2.165, "154 bp", col="grey30")

dev.off()