小技メモ(ggplot2に直線を引く)
@triadsouさんが紹介していたページの記事です。
http://stackoverflow.com/questions/6520758/adding-line-with-points-to-a-plot-in-ggplot2
library(ggplot2) addlinetoplot <- function(dataset, varx, vary) { list( geom_line(data=dataset, aes_string(x=varx, y=vary)), geom_point(data=dataset, aes_string(x=varx, y=vary)) ) } df1 <- data.frame(c1 = c(1:10), c2 = c(1:10)) c1 <- c(1:10) csq <- c1^2 df2 <- data.frame(c1 = c(1:10), csq) pltbase <- ggplot() + geom_line(data = df1, aes(x=c1, y=c2)) pltbase + addlinetoplot(df2, varx = "c1", vary = "csq")