I've installed ggplot2
3.1.0 on my PC. My raw data look like (short example of the long data frame):
structure(list(genotype = c("A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "C", "C", "C", "C", "C", "C", "C"),
type = c("M", "M", "M", "M", "M", "M", "M", "M", "M", "M",
"M", "M", "R", "R", "R", "R", "R", "R", "R")), row.names = c(NA,
19L), class = "data.frame")
I used the code to obtain the following plot :
library(ggplot2)
ggplot(df_test,aes(x=factor(genotype),fill=factor(type)))+geom_bar(stat="count")+xlab("Genotype")
But now i need to substitute the count by percentage, to show that 100% of the observations with genotype have type M and the same for genotype C (100% observations belong to type R). I tried to follow the post: enter link description here
My code was:
ggplot(df,aes(type,x=genotype,fill=type)+geom_bar(stat="identity")+xlab("Genotype")+scales::percent)
But got the error: Error in aes(y = type, x = genotype, fill = type) + geom_bar(stat = "identity") + : non-numeric argument to binary operator
Could you please help me to fix the error?