This question is similar to r - data frame of lists into a data frame but no answer was really sufficient.
I have a df
of time series data, comparing modeled to gage data. See below for a sub-section of the data:
Date GageFlow base0 1a 1b 2a 2b 3a
2003-10-01 78.6 72.43154 64.55318 64.55318 64.55318 64.55318 64.55318
2003-10-02 88.6 74.94789 68.48789 68.48789 68.48789 68.48789 68.48789
2003-10-03 96.6 75.08756 69.75530 69.75530 69.75530 69.75530 69.75530
2003-10-04 93.1 74.45323 66.67482 66.67482 66.67482 66.67482 66.67482
2003-10-05 90.2 72.89045 65.24120 65.24120 65.24120 65.24120 65.24120
2003-10-06 96.0 73.89078 67.88296 67.88296 67.88296 67.88296 67.88296
The str
of my data is:
'data.frame': 3653 obs. of 11 variables:
$ Date : Date, format: "2003-10-01" "2003-10-02" ...
$ GageFlow: num 78.6 88.6 96.6 93.1 90.2 96 96 97.8 98.7 99.8 ...
$ base0 :'data.frame': 3653 obs. of 1 variable:
..$ base0: num 72.4 74.9 75.1 74.5 72.9 ...
I would like to use ggplot
to make a plot of the modeled scenarios with geom_lines
of (base0
, 1a
, 1b
, etc.) and GageFlow
, with the x-axis
as the timeseries
(x=Date
) provided. The problem is that when I use melt
to try and get this in a tall format, I receive an error:
Error: Can't melt data.frames with non-atomic 'measure' columns In addition: Warning message: attributes are not identical across measure variables; they will be dropped
Do I actually need to restructure my df
or is there some way to melt
, or use another function to produce such a plot. Of course I could do this the long way, but I'm trying to become more efficient.
Thanks!