2016-11-04 2 views
1

x軸上にオメガでグループ化された蔓延〜デルタを示すバープロットが欲しい。デルタは8つのレベルを持っており、オメガは、私は、この例のように見えるために私のプロットをしたいと思い5.rggplot geom_barグループ化された位置

があります example ggplot

このプロットのためのコードを次のとおりです。

ggplot(data=dat1, aes(x=time, y=total_bill, fill=sex)) + 
    geom_bar(stat="identity", position=position_dodge(), colour="black") 

私のコードはどこプロットを作成デルタのレベルは、position = position_dodge()引数を使用しても、垂直方向に積み重ねられます。

ggplot(mydata, aes(x=omega, y=Prevalence, fill=delta)) + 
    geom_bar(stat = "identity", position = position_dodge()) 

my ggplot

私のデータ:

delta omega Prevalence 
1 0.0 0.0  0.040 
2 0.1 0.0  0.065 
3 0.2 0.0  0.082 
4 0.3 0.0  0.096 
5 0.5 0.0  0.118 
6 1.0 0.0  0.147 
7 2.0 0.0  0.162 
8 4.0 0.0  0.149 
9 0.0 0.3  0.072 
10 0.1 0.3  0.097 
11 0.2 0.3  0.114 
12 0.3 0.3  0.125 
13 0.5 0.3  0.140 
14 1.0 0.3  0.155 
15 2.0 0.3  0.155 
16 4.0 0.3  0.128 
17 0.0 0.5  0.083 
18 0.1 0.5  0.108 
19 0.2 0.5  0.123 
20 0.3 0.5  0.133 
21 0.5 0.5  0.145 
22 1.0 0.5  0.154 
23 2.0 0.5  0.146 
24 4.0 0.5  0.113 
25 0.0 0.7  0.090 
26 0.1 0.7  0.114 
27 0.2 0.7  0.128 
28 0.3 0.7  0.137 
29 0.5 0.7  0.146 
30 1.0 0.7  0.150 
31 2.0 0.7  0.135 
32 4.0 0.7  0.098 
33 0.0 1.0  0.095 
34 0.1 1.0  0.118 
35 0.2 1.0  0.130 
36 0.3 1.0  0.137 
37 0.5 1.0  0.142 
38 1.0 1.0  0.139 
39 2.0 1.0  0.118 
40 4.0 1.0  0.077 
+0

試し 'geom_bar(STAT = "アイデンティティ"、位置= "かわす")'の代わりに – Haboryme

答えて

1

ここでの問題は、デルタが数値としてコード化されていることです。単にそれを因子に変えればそれは機能します。

ggplot(mydata, aes(x=omega, y=Prevalence, fill=as.factor(delta))) + 
    geom_bar(stat = "identity", position = position_dodge()) 

enter image description here

関連する問題