在R

时间:2016-08-01 10:15:16

标签: r ggplot2 bar-chart

我融化了我的数据帧,其中包含两个组:“高”和“低”,它们都具有组中每个门的相对丰富度。我想创建一个堆积条形图,这样就有两列(高和低),并填充了100个门的百分比。

    Phylum          Group   value
1   Euryarchaeota   High    0.0000000000
2   Acidobacteria   High    0.0000000000
3   Actinobacteria  High    0.0014929190
4   Bacteroidetes   High    0.6620724580
5   Chloroflexi     High    0.0000000000
6   Cyanobacteria   High    0.0036403330
7   Elusimicrobia   High    0.0000000000
8   Fibrobacteres   High    0.0000000000
9   Firmicutes      High    0.3299947690
10  Fusobacteria    High    0.0008169250
11  GemmatimonadetesHigh    0.0000000000
12  Lentisphaerae   High    0.0000000000
13  Nitrospirae     High    0.0000000000
14  Planctomycetes  High    0.0000000000
15  Proteobacteria  High    0.0010844560
16  SR1             High    0.0000000000
17  Spirochaetes    High    0.0002579760
18  Synergistetes   High    0.0000000000
19  TM7             High    0.0000000000
20  Tenericutes     High    0.0000023900
21  Verrucomicrobia High    0.0006377750
22  [Thermi]        High    0.0000000000
23  Euryarchaeota   Low     0.0000018200
24  Acidobacteria   Low     0.0000015100
25  Actinobacteria  Low     0.0094485600
26  Bacteroidetes   Low     0.4611814500
27  Chloroflexi     Low     0.0000009090
28  Cyanobacteria   Low     0.0005776960
29  Elusimicrobia   Low     0.0000272000
30  Fibrobacteres   Low     0.0000001330
31  Firmicutes      Low     0.5217123900
32  Fusobacteria    Low     0.0005029220
33  GemmatimonadetesLow     0.0000003990
34  Lentisphaerae   Low     0.0000044400
35  Nitrospirae     Low     0.0000000444
36  Planctomycetes  Low     0.0000000222
37  Proteobacteria  Low     0.0027838720
38  SR1             Low     0.0000002440
39  Spirochaetes    Low     0.0000716000
40  Synergistetes   Low     0.0000093400
41  TM7             Low     0.0000555000
42  Tenericutes     Low     0.0013692220
43  Verrucomicrobia Low     0.0022507390
44  [Thermi]        Low     0.0000000222

我尝试过像这样的绘图: ggplot(df_long, aes(x = "Group", y = value, fill = Phylum)) geom_bar(stat = "identity")但情节空洞。

我之前使用df_long <- melt(data, id.vars = "Phylum", variable.name = "Group")

融合了我的数据框(如图所示)

为什么我的情节没有像我想的那样出现?

1 个答案:

答案 0 :(得分:0)

你需要在geom_bar函数中使用position =“stack”,如下所示:

ggplot(df_long, aes(Group, value, fill=Phylum)) + geom_bar(stat="identity",          
position="stack")