Hi:
Vivek's reply looks pretty good to me, but since you are new to this
game, I'll explain a bit how melt() works and why it's useful in this
situation for ggplot2.
The reshape2 package is designed to manipulate data from wide to long
form (melt()) or long to wide form (acast() or dcast()). In your case,
the right call is to reshape your data frame from wide to long. The
melt() function behaves somewhat like the stack() function in base R;
when the non-id (or 'measure') variables are stacked, two variables
are created: a factor named variable, which takes the original
variable names in long form and converts them to factor levels, and a
corresponding numeric variable named value. The 'constant' variable in
your original data frame is date, so it becomes the id variable. In
the melted data frame, it is recycled as many times as the number of
stacked variables. The resulting melted data frame has three
variables: date, variable and value.
The melted data frame is passed to ggplot(). The reason why this
approach works is because the faceting variable is normally a factor.
Also notice that the code is set up to plot value vs. date by
variable; the data structure returned by melt() made this possible.
The remaining options to facet_wrap() allow for vertical stacking of
the plots (ncol = 1) and free y-scales (scales = "free_y").
You can also plot dates on the horizontal axis in ggplot2; it is smart
enough to deduce if the x-variable is of class Date and plot a
set of default labels. I don't know what the time origin is of your
dates - I guessed it was Excel's default of 1 Jan 1900 based on a
little trial and error - let's pretend it is. Using Vivek's notation,
dfmelt$Date <- as.Date(dfmelt$date, origin = "1900-01-01")
ggplot(dfmelt, aes(x = Date, y = value)) +
geom_point() +
facet_wrap(~ variable, ncol = 1, scales = "free_y")
If the dates are wrong, modify the origin. If you want to change the
date scale, use the scale_x_date() function to change the breaks. To
change the labels, use the date_format() function from the scales
package. There are a few examples here; see section 7.1:
http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf
You can take your set of original ggplots, assign them to distinct
objects and use the grid.arrange() function in the gridExtra package
to accomplish the same task, but the differences in the magnitudes of
the y-axis labels will cause the left-side plot boundaries to be
misaligned. There are documented ways to fix the problem using the
gtable package, but the ggplot2 solution in this case is simpler and a
bit cleaner visually. Since you are new to ggplot2, simpler is better.
Dennis