"Error: Continuous value supplied to discrete scale" in default data set example mtcars and ggplot2 "Error: Continuous value supplied to discrete scale" in default data set example mtcars and ggplot2 r r

"Error: Continuous value supplied to discrete scale" in default data set example mtcars and ggplot2


Yeah, I was able to fix it by converting the color and shape aesthetics to factors:

ggplot(mtcars, aes(x=wt, y=mpg, color=as.factor(cyl), shape=as.factor(cyl))) +  geom_point() +   geom_smooth(method=lm, se=FALSE, fullrange=TRUE)+  scale_shape_manual(values=c(3, 16, 17))+   scale_color_manual(values=c('#999999','#E69F00', '#56B4E9'))+  theme(legend.position="top")


as.factor makes it work

ggplot(mtcars, aes(x=wt, y=mpg, color=as.factor(cyl), shape=as.factor(cyl))) +  geom_point() +   geom_smooth(method=lm, se=FALSE, fullrange=TRUE)+  scale_shape_manual(values=c(3, 16, 17))+   scale_color_manual(values=c('#999999','#E69F00', '#56B4E9'))+  theme(legend.position="top")