Reputation: 18229
set.seed(123)
library(data.table)
library(ggplot2)
dat=data.table(data.frame(a=rnorm(12),b=rnorm(12),c=rep(c(1,2),6),d=rep(c(1,2,3,4),3)))
ggplot(dat,aes(a,c,colour=d)) + geom_point() # line 1
ggplot(dat,aes(a,c,shape=d)) + geom_point() # line 2
Why is line 1 working but not line 2 ? Isn't it just a difference of how the plots are lookink ?
Thank you
Upvotes: 3
Views: 2416
Reputation: 132864
The error message tells you what's wrong:
Error: A continuous variable can not be mapped to shape
shape
needs a factor:
ggplot(dat,aes(a,c,shape=factor(d))) + geom_point()
Also check how ggplot(dat,aes(a,c,colour=factor(d))) + geom_point()
(a discrete colour scale) looks compared to the continuous colour scale.
Upvotes: 6