Reputation: 56149
I might be missing something very silly, can't get it to work. For example:
require(ggplot2)
#sample data
dat <- data.frame(x=1:5,
y=1:5,
z=1:5)
dat1 <- data.frame(x=1:5,
b=c(2,3,3,4,4))
Following works:
#This works:
ggplot(data=dat,aes(x=x,y=y,colour=z)) +
geom_point()
#This works, too:
ggplot(data=dat1,aes(x=x,y=b)) +
geom_line()
When I try to plot them together, it can't find z
:
Error in eval(expr, envir, enclos) : object 'z' not found
#This errors out
ggplot(data=dat,aes(x=x,y=y,colour=z)) +
geom_point() +
geom_line(data=dat1,aes(x=x,y=b))
EDIT:
Relevant post: add stripplot from different data.frame
Upvotes: 0
Views: 938
Reputation: 121568
For example:
ggplot() +
geom_point(data=dat,aes(x=x,y=y,colour=z)) +
geom_line(data=dat1,aes(x=x,y=b))
Upvotes: 2