df <- data.frame(sd = c('05AP.U1 1 ','05AP.U2 1','07RT.U1 1'),percentpl = c(50,40,80),percentan = c(50,60,20),count = c(100,100,100))
sd percentpl percentan count
1 05AP.U1 50 50 100
9 03KM.U2 40 60 100
12 07RT.U1 80 20 100
Is it possiple to draw a stacked,percent barplot onlyon the base of df
. I tried it with ggplot
but failed on the fill
variable.
ggplot(df, aes(fill=`percentpl`+`percentan`, y=count, x=`sd`)) +
geom_bar(position="fill", stat="identity")+ theme(axis.text = element_text(angle = 90))
I have seen couple of other similar questions R ggplot2 stacked barplot, percent on y axis, counts in bars Add percentage labels to a stacked barplot