Skip to content
Prev 274685 / 398506 Next

Scatterplot with the 3rd dimension = color?

Here's my loadable data in case it helps. It creates 2 separate plots
which I'd like to be in the same graph with 2 separate legends.

library(ggplot2)

#Here's the 1st plot
x<-rnorm(100)
y<-rnorm(100)
z<-rnorm(100)
d <- data.frame(x,y,z)
dg<-qplot(x,y,colour=z,data=d)
dg + scale_colour_gradient(low="red", high="blue")

#Here's the 2nd plot which will delete the 1st plot above but I'd like
them to be plotted together
x1<-rnorm(100)
y2<-rnorm(100)
z3<-rnorm(100)
d1 <- data.frame(x1,y1,z1)
dg1 <-qplot(x1,y1,colour=z1,data=d1)
dg1 + scale_colour_gradient(low="green", high="yellow")

Thanks,
kb
On Oct 2, 10:42?pm, Ben Bolker <bbol... at gmail.com> wrote: