Prevalences with ggplot

Hi all,

I would like to create a barplot with the prevalences of infections according to different sites.

I'm obtaining a plot counting the number of infected individuals on each site in y, but I would like the prevalences (number of infected/total individuals on the site).

library(ggplot2)
#> Warning: le package 'ggplot2' a été compilé avec la version R 4.1.3
df <- data.frame(
  stringsAsFactors = FALSE,
         SITE_NAME = c("Guadarrama","Guadarrama",
                       "Guadarrama","Guadarrama","Guadarrama","Guadarrama",
                       "Guadarrama","Guadarrama","Guadarrama","Guadarrama",
                       "Guadarrama","Guadarrama","Guadarrama","Guadarrama",
                       "Guadarrama","Guadarrama","Guadarrama","Guadarrama",
                       "Guadarrama","Guadarrama","Guadarrama","Guadarrama",
                       "Sierra de la Demanda","Sierra de la Demanda",
                       "Sierra de la Demanda","Sierra de la Demanda","Sierra de la Demanda",
                       "Sierra de la Demanda","Sierra de la Demanda",
                       "Sierra de la Demanda"),
             Haemo = c(0,1,0,0,0,1,0,0,0,0,1,
                       0,0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,1,0,0)
)

ggplot(data=df, aes(x=SITE_NAME, y=Haemo)) +
  geom_bar(stat="identity")

Created on 2022-05-22 by the reprex package (v2.0.1)

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.