0
votes

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

1

1 Answers

1
votes

For example:

ggplot() +
  geom_point(data=dat,aes(x=x,y=y,colour=z)) +
  geom_line(data=dat1,aes(x=x,y=b))