Thought it would be easy but am running out of ideas here. I have three data.frame that I would like to plot in a single figure such that plot-A would contain line plots using data of column A from all the data.frame i.e., DF1,DF2,DF3, plot-B should contain line plots using data of column B from all data.frame and likewise for C. In the past I use facet_wrap, however, I have no idea how to go about this. here is my simple code which does not produce any plot but will give an idea what I want. A ggplot option would be great.
library(gridExtra)
DF1 = data.frame(Month = 1:12, A = runif(12, 1,10), B = runif(12,5,10), C = runif(12, 3,9))
DF2 = data.frame(Month = 1:12, A = runif(12, 4,13), B = runif(12,6,14), C = runif(12, 3,12))
DF3 = data.frame(Month = 1:12, A = runif(12, 2,15), B = runif(12,1,9), C = runif(12, 3,15))
G1 = plot(DF1$Month, y=DF1$A, "l")
lines(DF2$A, col = "red")
lines(DF3$A, col = "blue")
G2 = plot(DF1$Month, y=DF1$B, "l")
lines(DF2$B, col = "red")
lines(DF3$B, col = "blue")
G3 = plot(DF1$Month, y=DF1$C, "l")
lines(DF2$C, col = "red")
lines(DF3$C, col = "blue")
grid.arrange(G1,G2,G3, ncol = 3)
Note:
in my example, I have three columns in each data.frame, however, I would like to apply the code over data.frame that have a large number of columns- not just three. so automating the process would help.
y=but neitherx=nortype=?)xwould be same for all- irresepective ofdata.frameused. I was just trying to convey my message, we can definitely usetypewith additional feature ofplotfunctionality.x=and to namey=and not nametype=is not invalid code, but it seems to straddle code practice/convention, that's all. Like I said, I'm just curious about that one, it is not meant as judgement or a criticism. (BTW: based on your comment to Louis, I suggest you need to be a little clearer in your question that you are trying to automate this based on larger numbers of columns. It's generally a good reproducible question, but that part was not clear to me either.)