Saturday, 24 August 2013

Easy way to view multiple Y variables against same X

Easy way to view multiple Y variables against same X

I want to visualize many time series at once. I am new at R, and have
spent about 6 hours searching the web and reading about how to tackle this
relatively simple problem. My dataset has five time points arranged as
rows, and 100 columns. I can easily plot any column against the time
points [qplot(time, var2, geom="line"). But I want to learn how to do this
for a flexible number of columns, and how to print 6 to 12 of the
individual graphs on one page.
Here I learned about the multiplot function, got that to work in terms of
layout.
What I am stuck on is how for get the list of variables into a FOR
statement so I can have one statement to plot all the variables against
the same five time points.
this is what I am playing with. It makes 9 plots, 3 columns wide, but I do
not know how to get all my variables into the array for yvars?
for (i in 1:9) {
+ p1 = qplot(symbol,yvar, geom ="smooth", main = i))
+ plots[[i]] <- p1 # add each plot into plot list
+ }
multiplot(plotlist = plots, cols = 3)
Stupidly on my part right now it makes 9 identical plots. So how do I
create the list so the above will cycle through all my columns and make
those plots?
Thank you,

No comments:

Post a Comment