[英]Multiple splines on the same plot with ggplot2?
假设您最初在两个data.frames中拥有所需的数据,则此代码将起作用。 使用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)
如果您的数据位于data.frame的不同列中,请使用reshape2 :: melt处理它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.