[R] plot many dfs in ggplot

lily li chocold12 at gmail.com
Tue Aug 2 20:50:41 CEST 2016


Hi all,

I have another question. There are several dataframes, each has the same
columns: time, varA, varB, varC, etc. If I want to plot time ~ varA of each
dataframe, where different dataframe names use different colors. How to do
this in ggplot? Thanks for your help.

Right now, I tried to use the code below, but very laborious, and needs
colors manually.

fig1 = ggplot()+
    geom_path(data=df1, aes(x=time, y= varA, color= 'df1'))+
    geom_path(data=df2, aes(x=time, y= varA, color= 'df2'))+
    geom_path(data=df3, aes(x=time, y= varA, color= 'df3'))+
    ...
    scale_color_manual('', limits=c('df1', 'df2', 'df3', ...),
values=c('blue', red', 'green', ...))
show(fig1)

	[[alternative HTML version deleted]]



More information about the R-help mailing list