Code : Tout sélectionner
library(ggplot2)
library(scales)
library(dplyr);
#Definition of data
graph<-cbind.data.frame(
sample(c("FI", "FA","FC"), 100, replace = TRUE),
sample(c("Rep","Dip"),100, replace=TRUE)
)
names(graph)<- c("RegimeInscription","repondant")
tabl <- graph %>% table() %>% prop.table(2) %>% data.frame() %>% group_by(repondant) %>% mutate(pos = cumsum(Freq) - (0.5 * Freq))
#Some var
theme_barre <- theme_bw()+
theme(
panel.grid=element_blank(),
plot.title=element_text(colour = 'red', size=10, face="bold", hjust = 0.5, vjust = 0.5),
legend.text=element_text(size=9),
legend.key.size = unit(2, "mm"),
panel.background = element_rect(fill = "transparent",colour = NA), # or theme_blank()
plot.background = element_rect(fill = "transparent",colour = NA),
panel.grid.minor = element_blank()#,
)
#Make the graph
tabl <- graph[,c("repondant","RegimeInscription")] %>% table() %>% prop.table(1) %>% data.frame() %>% group_by(repondant) %>% mutate(pos = cumsum(Freq) - (0.5 * Freq))
ggplot(tabl, aes(x = factor(repondant), y=Freq, fill = factor(RegimeInscription) )) +#Initiation du graphique
geom_bar(position = "fill", stat="identity")+ #Realisation du graphique
theme_barre + #fond blanc
coord_flip()+ #barre horizontale
scale_fill_discrete( name=" ", labels=c("FI"="Fi","FA"="Fa","FC"="Fc") )+
labs(x=" ", y=" ")+
scale_y_continuous(breaks=seq(0,1,0.1), labels=percent)+
ggtitle("Régime d'inscription")+
geom_text( mapping = aes(x= factor(repondant), y = pos, label = lab(Freq) ),size=3)
Cependant quand je change les données par mes données personnelles j'ai le résultat suivant :
Auriez vous une idée du pourquoi du comment ?
Merci