I try to plot multiple lines in single plot as follow:
y <- matrix(rnorm(100), 10, 10)
m <- qplot(NULL)
for(i in 1:10) {
m <- m + geom_line(aes(x = 1:10, y = y[,i]))
}
plot(m)
However, it seems that qplot
will parse m
during plot(m)
where i
is 10
, so plot(m)
produces single line only.
What I expect to see is similar to:
plot(1,1,type='n', ylim=range(y), xlim=c(1,10))
for(i in 1:10) {
lines(1:10, y[,i])
}
which should contain 10 different lines.
Is there ggplot2
way to do this?