X轴上的连续Barplot,没有空格

时间:2019-06-22 07:59:56

标签: r ggplot2 geom-bar

我正在尝试创建一个堆叠的条形图,其中包含不同年龄段的基因型分布。我已经走了很远,但是现在我不知道如何解决我的问题:两个绘图之间的x轴上有一个空间。如何删除空白。我猜这是因为我的X值不是连续的,但是我不知道如何更改脚本。此外,如果有人可以帮助我增加观察次数(每个年龄段为30个),我将不胜感激。

我试图将年龄向量放入字符中,但这仅导致X轴完全重新布置

这是我完整的脚本:

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

我希望在7岁到10岁之间没有空格。此外,我想在每个栏的上方添加观察次数(每个年龄段30个)(我知道已经发布了一些脚本,但我没有设法将其应用到脚本中。)

0 个答案:

没有答案