Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Increase size of geom_point for one factor level

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)

enter image description here

I do not want to use the size option here:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading