[Solved] Stacked barplot with percentage in R ggplot2 for categorical variables from scratch


enter image description hereI used solution provided by NelsonGon, but maked it a bit shorter. Besides i always try to avoid of using third party libraries if it’s possible. So the code working for me was:

ggplot(df_test,aes(x=factor(genotype),fill=factor(type)))+geom_bar(position="fill")+xlab("Genotype")+scale_y_continuous(labels=scales::percent_format())

solved Stacked barplot with percentage in R ggplot2 for categorical variables from scratch