简体   繁体   中英

r plot different data.frames on the same graph

I have a list of 4 data.frames which different names which look like:

date x

01-03-2012 0.66

01-06-2014 0.44

...

What I need: I need a plot with for colored sets of dots. Each set of dots should correspond to one data frame. Date ranges are different (one data.frame may start in 2011 and another - in 2012)

I tried to make this

plot(x~date,toplot$a,xlab = "date", ylab = "value" , type= "o", col="red )

points(toplot$b$date, toplot$b$x,col="green") points(toplot$c$date, toplot$c$x,col="black") points(toplot$d$date, toplot$d$x,col="blue")

But the first command draws small black lines instead of points, although type= "o" and doesn't change color to red toplot is a list of data.frames, a,b,c,d - are data.frames.

If I add another data.frame data with par(new=TRUE) and another plot command, small black lines for both data.frames are drawn. The same situation with plot(..., add=TRUE)

Thank you in advance.

First: for a point plot you use type="p" or nothing, because it plots points as default. Second: in the Code you showed here a " is missing in col="red" but this should give an error or at least the command is not executed, because R waits for the closing "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM