Replacing count by percentage in R

I have the following code :

  mutate( bmi = Gewicht / (Körpergröße/100)^2 ) %%
  filter( Lebensalter = 18 )%%
  filter(!is.na(bmi))%%
  group_by(Geschlecht, Ethnie)%%
  filter(!is.na(Ratio))%%
  mutate (Poor = Ratio  1.3)%%
  mutate (Adipös= bmi=30)%%
  filter(!is.na(Poor))%%
  ggplot+
  geom_histogram(aes( y= Poor, fill=Adipös), stat = count)+
  facet_grid(Ethnie~Geschlecht) 

which gives me this table:

How can I get the percentage for each true and false for poor and adipös? E.g. 20% of male poor African American are also Adipös (overweight)? So instead of the bars showing the count I would have the percentage.

Topic homework data-analysis data statistics r

Category Data Science


I didn't test it, but I think you can just add position = "fill" like this:

ggplot+
  geom_histogram(aes( y= Poor, fill=Adipös), position = "fill")+
  facet_grid(Ethnie~Geschlecht) 

If I'm not mistaken stat='count' is optional.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.