Reputation: 623
I'm trying to make a plot with two y-variables with different shape and color, but I keep failing.
Any suggestions as to where I go wrong?
library (ggplot2)
library (forcats)
ggplot(mtcars, aes(x=disp, y=drat, group=as_factor(vs)))+
geom_point(aes(shape=as_factor(vs), color=as_factor(vs))) +
scale_shape_manual(values=c(21, 24))+
scale_fill_manual(values=c("black", "yellow")) +
theme_bw() +
facet_wrap(vars(cyl))
ggplot(mtcars, aes(x=disp, y=drat, shape=as_factor(vs)))+
geom_point() +
scale_shape_manual(values=c(21, 24))+
scale_fill_manual(values=c("black", "yellow")) +
theme_bw() +
facet_wrap(vars(cyl))
Upvotes: 0
Views: 39
Reputation: 731
Be careful to use as.factor (not as_factor), and watch out for typos. Here is the corrected code:
library(ggplot2)
ggplot(mtcars, aes(x=disp, y=drat, group=as.factor(vs)))+
geom_point(aes(shape=as.factor(vs), color=as.factor(vs))) +
scale_shape_manual(values=c(21, 24))+
scale_fill_manual(values=c("black", "yellow")) +
theme_bw() +
facet_wrap(vars(cyl))
Upvotes: 1