Say I like to increase the size of only those data points where the factor variable cyl == 6. How can I do that?
ggplot(mtcars, aes(x = qsec , y = mpg, col = as.factor(cyl ))) +
geom_point(size= 2)
I do not want to use the size option here:
ggplot(mtcars, aes(x = qsec , y = mpg, col = as.factor(cyl), size = as.factor(cyl))) +
geom_point()
because it uses size for all factor levels.
>Solution :
Another way is to use ifelse to assign size.
library(ggplot2)
ggplot(mtcars, aes(x = qsec , y = mpg, col = as.factor(cyl), size = ifelse(cyl == 6, 4, 3))) +
geom_point() +
guides(size = 'none')

Created on 2023-03-09 with reprex v2.0.2
