Hi all,
I have some problems in plotting time series data. For example, I have several datasets, df1, df2, df3, etc., while each dataset has the same structure. Different datasets represent flow at different gauges.
df1
year month day flow time
2002 1 1 5 2002-01-01
2002 1 2 6 2002-01-02
2002 1 3 5.5 2002-01-03
...
df2
year month day flow time
2002 1 1 7.5 2002-01-01
2002 1 2 8 2002-01-02
2002 1 3 7.6 2002-01-03
...
I tried to plot daily time-series data, using the code:
p1 = ggplot()+ geom_line(data=df1,aes(x=time,y=flow,color='DF1') + geom_line(data=df2,aes(x=time,y=flow,color='DF2') + scale_color_manual('',limits=c('DF1', 'DF2'), values=c('red', 'blue'))
print(p1)
Now I want to plot annual values, but got no luck. Could anyone tell me the problem? Thanks.
df1.yr = aggregate(flow~year, data=df1, sum)
df2.yr = aggregate(flow~year, data=df2, sum)
...
p2 = ggplot()+ geom_line(data=df1.yr, aes(x=year,y=flow, color='DF1.yr')+ geom_line(data=df2.yr, aes(x=year,y=flow,color='DF2.yr')+ scale_color_manual('', limits=c('DF2.yr', 'DF2.yr'), values=c('red','blue'))
print(p2)
It has the error message:
Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
Error in data.frame(x =, y= function (save = 'default', status=0, :arguments imply differing number of rows: