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

Adding color to histogram using ggplot and facet_wrap

I need help adding color to the two histograms produced using ggplot and facet_wrap

What am I missing:

ObesityDataSet_raw_and_data_sinthetic %>%
  ggplot(aes(x=Height)) +
  geom_histogram(bins = 14)+
  facet_wrap(~Gender)

It would look like this

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

Need

>Solution :

To add color to the histograms in ggplot and facet_wrap, you can use the fill argument in the geom_histogram function to specify the color for each histogram. Here’s an example code:

ObesityDataSet_raw_and_data_sinthetic %>%
  ggplot(aes(x=Height, fill=Gender)) +
  geom_histogram(bins = 14, alpha=0.5, position = "identity")+
  facet_wrap(~Gender)

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