I'm trying to create a stacked barplot with the distribution of genotype at different ages. I have come quite far, but now I don't know how to solve my problem: There is a space in my x-axis between two plots. How can I remove this blank. I guess it is because my X-values are not continous, but I don't know how to change the script. Furthermore, if anyone can help me to add the number of observation (30 for each age) I would be really grateful.
I tried to put the age vector into characters, but that only led that the X-Axis was completly rearranged
This is my complete script:
Age<-c(4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,10,10,10,10,11,11,11,11,12,12,12,12)
Genotype<-c("UN", "HM", "HT", "WT","UN", "HM", "HT", "WT","UN", "HM", "HT", "WT","UN", "HM", "HT", "WT","UN","HM", "HT", "WT","UN","HM", "HT", "WT","UN","HM", "HT", "WT")
Percentage<-c(6.7, 26.7, 23.3, 43.3, 10, 13.3, 26.6, 50, 0, 36.6, 23.3, 40, 13.4, 40, 33.3, 13.3, 6.8, 26.6, 40, 26.6, 10, 23.3, 53.3, 13.3, 13.4, 20, 63.3, 3.4)
Plastics_sec<-data.frame(Age, Genotype, Percentage)
Plastics_sec$Genotype<- factor(Plastics_sec$Genotype, levels = c("UN","HM","HT", "WT"), labels = c("Undefined", "Homozygous","Heterozygous", "Wildtype"))
fill<-c("khaki1", "brown1", "darkolivegreen3", "deepskyblue3")
plot1<- ggplot() + geom_bar(aes(y = Percentage, x = Age, fill = Genotype), data = Plastics_sec, stat="identity")+ theme(legend.position="right", legend.direction="vertical", legend.title = element_blank()) + labs(x="Age", y="Percentage") + scale_y_continuous(labels = dollar_format(suffix = "%", prefix = "")) + ggtitle("BBS4 Genotype at different ages")+scale_fill_manual(values = fill)
plot1
I would like, taht there is no space between Age 7 and 10. And furthermore I would like to add the number of observation (30 for each age) on top of each bar (I know there is already some scripted posted, but I didn't manage to apply it to my script).