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

GGplot2 How to change outlier shape per boxplot group?

I would like to distinguish every boxplot’s outliers by shape. For example boxplot 1 uses crosses, boxplot 2 uses circles etc.
I tried to achieve this by doing

ggplot(diamonds, aes(x = cut, y = price)) + geom_boxplot(outlier.shape = c(0, 1, 2, 3, 4))

and by simply doing

ggplot(diamonds, aes(x=cut, y=price, shape=cut)) + geom_boxplot()

Both options fail. How can I achieve different outlier shapes for each boxplot?

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

>Solution :

You could use the outlier.shape argument have to assign them by NULL like this:

library(ggplot2)
ggplot(diamonds, aes(x=cut, y=price, shape = cut)) + 
  geom_boxplot(outlier.shape=NULL)

Created on 2023-10-27 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