1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
library(ggplot2) # pour création graphes ggplot
library(tidyverse) # pour les fonctions fct_reorder / stringr / ddply
library(plyr) # pour la fonction ddply
# Réalisation dune dataframe test
Type_etablissement <- rep ( c("CLCC","CHU","CHU") , 6 )
Presence_manip_bloc <- rep ( c("OUI","NON") , 9 )
DFtest <- data.frame (Type_etablissement, Presence_manip_bloc )
#calcul pourcentage dobservations pour chaque Type_etablissement:
annot_pourcent <- DFtest %>%
group_by(Type_etablissement) %>%
dplyr::summarise(nb = n()) %>%
ungroup() %>%
mutate(pourcentage = paste0(round(nb/sum(nb)*100,1), " %") )
gg <- ggplot(DFtest) +
aes(x=reorder(Type_etablissement, Type_etablissement, function(x)- length(x))) +
geom_bar(stat="count", aes(fill= Presence_manip_bloc), colour="black", width=0.6) +
coord_flip(ylim=c(0,15))+
geom_text (annot_pourcent, mapping= aes(y=nb, label=pourcentage), hjust=-0.25, size=3)
#ajout du texte « essai »
gg+ annotate("text", x=2, y=10, label="essai", colour="red", size=7, fontface="bold")
gg |
Partager