I have a dataset with multiple species and a flag (Yes/No).
I want to display in a stacked histogram the proportion of Yes/No for several condition. Below is a minimal code with what I want to achieve:
# create a dataset
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition <- rep(c("Y" , "N") , 6)
type <- rep(c("grass" , "tree" , "algea"), 4)
data <- data.frame(specie,condition,type)
Plot
ggplot(data, aes(fill=condition, y=condition, x=specie)) +
geom_bar(position="stack", stat="identity")
ggtitle("Studying 4 species..")
As you can see the y-axis is not correct, instead of showing count,it shows Y/N.
I am fully aware that by sumarising/grouping I could easily achieve what I am looking for, but I was looking to have a versatile way where I can switch with facet wrap with the type condition easily (my real dataset has multiple "type" column that I could use).
Any help would be much appreciated ;-) Thank you,