【发布时间】:2019-06-25 08:53:42
【问题描述】:
我有这张桌子:
Number Type Correction Adjust Origin
1061 60-15 Corrected yes Small RNA-seq
204 60-15 Corrected no Small RNA-seq
0 60-15 Native yes Small RNA-seq
540 60-15 Native no Small RNA-seq
0 60-30 Corrected yes Small RNA-seq
315 60-30 Corrected no Small RNA-seq
0 60-30 Native yes Small RNA-seq
58 60-30 Native no Small RNA-seq
0 70-15 Corrected yes Small RNA-seq
200 70-15 Corrected no Small RNA-seq
0 70-15 Native yes Small RNA-seq
61 70-15 Native no Small RNA-seq
0 70-30 Corrected yes Small RNA-seq
259 70-30 Corrected no Small RNA-seq
0 70-30 Native yes Small RNA-seq
42 70-30 Native no Small RNA-seq
0 80-15 Corrected yes Small RNA-seq
166 80-15 Corrected no Small RNA-seq
0 80-15 Native yes Small RNA-seq
76 80-15 Native no Small RNA-seq
0 80-30 Corrected yes Small RNA-seq
182 80-30 Corrected no Small RNA-seq
0 80-30 Native yes Small RNA-seq
13 80-30 Native no Small RNA-seq
我在 ggplot2 中生成了以下图,这几乎是我想要的:
ggplot(Table, aes(fill=Correction, x=Type, y=Number)) +
geom_bar(position="dodge", stat="identity") +
scale_fill_brewer(palette = "Set1") + labs(x="", y="") +
theme(legend.title=element_blank()) + facet_wrap(~Origin)
生成一个像这样的图形:
问题是我希望将 60-15 的第一个条分成两部分(1061 和 204),就好像它是一个堆叠的条形图一样。其余的条没有这种特殊性,并且将保持不变。我尝试通过添加数值为零的行来解决此问题,但我找不到解决此问题的正确代码。
有人可以帮忙吗?
谢谢
【问题讨论】:
-
我认为你的情节是错误的,因为你的 60-15 校正条的最大值是 1061 而不是 (1061 + 204),对吧?
-
是的,我认为那是因为剧情只占用了第一行而不是第二行
-
能否请您发布
dput(Table)的输出?
标签: r ggplot2 bar-chart stacked