我有一个使用此代码创建的数据框:
require(reshape2)
foo <- data.frame( abs( cbind(rnorm(3),rnorm(3, mean=.8),rnorm(3, mean=.9),rnorm(3, mean=1))))
qux <- data.frame( abs( cbind(rnorm(3),rnorm(3, mean=.3),rnorm(3, mean=.4),rnorm(1, mean=2))))
bar <- data.frame( abs( cbind(rnorm(3,mean=.4),rnorm(3, mean=.3),rnorm(3, mean=.9),rnorm(3, mean=1))))
colnames(foo) <- c("w","x","y","z")
colnames(qux) <- c("w","x","y","z")
colnames(bar) <- c("w","x","y","z")
rownames(foo) <- c("n","q","r")
rownames(qux) <- c("n","q","r")
rownames(bar) <- c("n","q","r")
foo <- cbind(ID=rownames(foo),foo)
bar <- cbind(ID=rownames(bar),qux)
qux <- cbind(ID=rownames(bar),qux)
foo$fn <- "foo"
qux$fn <- "qux"
bar$fn <- "bar"
alldf<-rbind(foo,qux,bar)
alldf.m <- melt(alldf)
我想要做的是创建一个刻面ggplot
格式的线曲线,所以它会创建一个像这样的图形:
实际的图表不包含向上的线 - 这只是一个草图,以便线条分离清晰。
我当前的代码不起作用:
library(ggplot2)
p <- ggplot(data=alldf.m, aes(x=variable)) +
geom_line(aes(colour=ID),alpha=0.4)
p <- p + facet_wrap( ~ fn)
p
最好的方法是什么?