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

Why is only the first boxplot changing color?

I’ve written the following code to create a boxplot with multiple groups. I want each plot to be a different specified color but I can only seem to alter the first one in the series. I can change the first "blue" to any color but the other plots always stay gray. Any idea what I need to fix?

`ggplot(Boxplots, aes(x=SiteName, y= Concentration, fill=SiteName)) + geom_boxplot() + scale_y_log10() + theme_bw() + scale_fill_manual(breaks= Boxplots$SiteName, values= c("blue", "cornflowerblue","cyan", "red", "darkred", "maroon")) enter image description 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

>Solution :

Try to move fill=SiteName from aes() to geom_boxplot() and remove breaks= Boxplots$SiteName, from scale_fill_manual()like this:

 ggplot(Boxplots, aes(x=SiteName, y= Concentration)) +
      geom_boxplot(fill=SiteName) + scale_y_log10() + theme_bw() +
       scale_fill_manual(values= c("blue", "cornflowerblue","cyan", 
       "red", "darkred", "maroon"))
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