r - Multiple splines on the same plot with ggplot2? -
i add other spline plot below, if geom_point()
display points on first spline.
n <- 10 d <- data.frame(x = 1:n, y = rnorm(n)) ggplot(d,aes(x,y)) + geom_point() + geom_line(data=data.frame(spline(d, n=n*10)))
how can display dots on second line too?
assuming have data want in 2 data.frames, code work. makes spline before using ggplot.
n <- 10 d <- data.frame(x = 1:n, y = rnorm(n)) d2 <- data.frame(x = 1:n, y = rnorm(n)) dd <- rbind(cbind(d, case = "d"), cbind(d2, case = "d2")) ddsmooth <- plyr::ddply(dd, .(case), function(k) as.data.frame(spline(k, n = n * 10))) ggplot(dd,aes(x, y, group = case)) + geom_point() + geom_line(aes(x, y, group = case), data = ddsmooth)
if data in different columns of data.frame, use reshape2::melt process it.
Comments
Post a Comment