我想用轴中变量的绝对值创建堆积条形图,但在每个条形上添加百分比。这是我的数据的样子:
BAM Mapping Reads fraction
bam1 Mapped 22493091 0.88940452
bam1 Unmapped 2796966 0.11059548
bam2 Mapped 27018375 0.88256156
bam3 Unmapped 3595212 0.11743844
bam3 Mapped 27238774 0.89441821
bam4 Unmapped 3215407 0.10558179
bam4 Mapped 19791746 0.82984107
bam4 Unmapped 4058298 0.17015893
bam5 Mapped 23298155 0.83144569
bam5 Unmapped 4723104 0.16855431
bam6 Mapped 22563538 0.83990722
bam6 Unmapped 4300784 0.16009278
bam7 Mapped 23940480 0.88134856
bam7 Unmapped 3222984 0.11865144
我快到了(别管 x-labels - 我在这里使用长名称):
gp <- ggplot(data=to_graph, aes(x=BAM, y=Reads, fill=Mapping, label=paste(round(fraction*100),"%", sep=""), size = 3,vjust=0, position = "stack")) +
geom_bar(stat="identity") +
geom_text(position="stack")
但是在我想摆脱的传说之上还有一个小问题。重要的是如何做到这一点,为什么它会出现在第一位?
干杯。