0

Supose I have this tree dataframes, where the first row represents a place and first colum represents a day.

z<-c("a", 2, 3)
x<-c("b",2,3)
y<-c("c",4,5)


w<-c("a",5,3)
v<-c("b",6,5)
r<-c("c",2,1)

q<-c("a",2,5)
p<-c("b",4,5)
t<-c("c",2,1)

g<-c(NA,1,2)

df1<-data.frame(g, z,x,y)
df2<-data.frame(g, w,v,r)
df3<-data.frame(g, q,p,t)

I want to plot several graphics containing the information of the 3 dataframes. I want to represent the values of df1, df2 and df3, in the graphic for each day and place. So for example, I want to plot for day 1, df1, df2, df3, and so on. An the same for place a, i want to plot df1, df2, df3.

L8call
  • 87
  • 1
  • 1
  • 6
  • 1
    Please show what you've tried so far and where you failed. – Roman Luštrik Jun 22 '18 at 19:09
  • I don't know any function for ploting diferent dataframes in the same plot.. – L8call Jun 22 '18 at 19:13
  • 1
    What are the "days" and "places" supposed to be in this case? And this sample data doesn't make much sense. You can't have character values and numeric values in the same vector. Everything will just be coerced into a character. Maybe you can draw a sketch of the desired output for this sample data. Most likely things will be easier if you just merge the three data.frames before plotting. – MrFlick Jun 22 '18 at 19:19
  • Do you want 3 plots size by side in the same plot? Do you want the lines to be layered on a single plot? This probably has your answer: https://stackoverflow.com/questions/2564258/plot-two-graphs-in-same-plot-in-r?rq=1 – divibisan Jun 22 '18 at 19:19
  • Possible duplicate of [Plot two graphs in same plot in R](https://stackoverflow.com/questions/2564258/plot-two-graphs-in-same-plot-in-r) – divibisan Jun 22 '18 at 19:19
  • I don't think it is duplicated, because I need to plot two graphics (number of days, taht in reality are 76), with the lines of the 3 dataframes, and later I want to plot the places (which are 35). @divibisan – L8call Jun 22 '18 at 19:23
  • @MrFlick days are represented by 1,2 and places by a,b,c. This is dummy data to be easier. the numbers in the middle are what's going to be in my graphic. – L8call Jun 22 '18 at 19:24
  • 2
    If you were willing to use `ggplot()` instead of `plot()`, it is fairly easy: `ggplot() + geom_line(data = df1 ...) + geom_line(data = df2 ...) + geom_line(data = df3 ...)`. You simply specify that each `geom_line` uses a different data frame, and they are all plotted together. – sam Jun 22 '18 at 19:35
  • 1
    All plotting functions in R, either in base or in higher level packages can plot data from arbitrary sources, as they all accept passing references to vectors from different data frames or matrices. The tricky part is how to map the different vectors (data series) to different plot properties... You need to be more specific about what you want plotted and how, where the data comes from is secondary. – jtatria Jun 22 '18 at 19:36
  • @gorgonzola in this case I want 5 plots: one that gives me day 1 with three lines corresponding to df1, df2, df3 with the values of a,b,c in their x axis. the same for day 2 then, I need on for a, with 3 lines df1, df2, df3, that gives me the value in day 1 and 2; another plot for b and c. – L8call Jun 22 '18 at 21:34

1 Answers1

0

See ?par and the mfrow argument. You can set the value for mfrow to define how many rows and columns of plots you want in a grid.

https://www.statmethods.net/advgraphs/layout.html

JMT2080AD
  • 1,049
  • 8
  • 15