I'm using this R code:
library(ggplot2)
library(dplyr)
library(scales)
library(RColorBrewer)
#q5
d=data.frame(
rbind(as.data.frame(table(data$q5_a))[2,2],
as.data.frame(table(data$q5_b))[2,2],
as.data.frame(table(data$q5_c))[2,2],
as.data.frame(table(data$q5_d))[2,2],
as.data.frame(table(data$q5_e))[2,2],
as.data.frame(table(data$q5_f))[2,2],
as.data.frame(table(data$q5_g))[2,2],
as.data.frame(table(data$q5_h))[2,2]))
d[is.na(d)] <-0
colnames(d)="Freq"
df=data.frame(Pourcentage=round((d$Freq/61),2),
Motivation=c("Proximité","Sécurité et confiance",
"Souplesse dans la procédure","Services adaptés à mes besoins",
"Faiblesse des coûts","Célérité dans le traitement des opérations",
"Accessibilité et simplicité des services" ,"Autres"))
df$Pourcentage <-factor(df$Pourcentage,
levels=df[order(df$Motivation), "Motivation"])
p=ggplot(data=df, aes(x=Motivation, y=Pourcentage, fill=Motivation)) +
geom_bar(stat="identity",width=0.5,fill="purple", colour="darkblue")+
geom_text(aes(label=percent(Pourcentage)), hjust=1.4,
color="white",size=3.5)+
theme_minimal()+
ggtitle("Quelles sont les motivatons de votre choix ?")+
scale_y_continuous(labels=percent,,breaks=NULL)+ theme_classic()+
coord_flip()
p + theme(
axis.title.x = element_blank(),
axis.title.y = element_blank())
And i get this plot as output
The problem is that i want to rearange bars with a predefined order to optimize my plot