2013-07-31 26 views
2

我正在利用R中的ggplot2軟件包通過計數來繪製功能類別。正如下圖所示,這些類別是按蛋白質計數排序的,也是根據它們所屬的類別排序的。在ggplot2中按類別劃分條形圖,同時保留Y軸的標籤結構

enter image description here

這裏是我參與工作的數據集的部分:

GO_Category        protein_count Class 
aromatic amino acid family metabolic process  24 Amino acid metabolism 
glutamine family amino acid metabolic process  14 Amino acid metabolism 
aspartate family amino acid metabolic process  10 Amino acid metabolism 
glutamine family amino acid biosynthetic process 9 Amino acid metabolism 
branched-chain amino acid metabolic process   8 Amino acid metabolism 
peptidyl-lysine modification to hypusine   4 Amino acid metabolism 
ornithine metabolic process       3 Amino acid metabolism 
single-organism carbohydrate metabolic process  125 Carbohydrate metabolism 
carbohydrate biosynthetic process     55 Carbohydrate metabolism 
pentose metabolic process       7 Carbohydrate metabolism 
mannose metabolic process       3 Carbohydrate metabolism 
organelle organization        101 Cellular components 
ribonucleoprotein complex biogenesis    41 Cellular components 
plastid organization        35 Cellular components 

這裏是一個代碼,我使用R:

nameorder <- df$GO_Category[order(df$Class, df$protein_count)] 
df$GO_Category <- factor(df$GO_Category, levels=nameorder) 
ggplot(data=df, aes(x=GO_Category, y=protein_count, fill=GO_Category)) + 
    geom_bar(color="black", stat="identity", width=0.5, position=position_dodge(.5)) + 
    coord_flip() + 
    guides(fill=FALSE) + 
    ylab("Protein Association Count") + xlab("Gene Ontology Category") + 
    theme(panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank(), axis.text.y=element_text(colour="#999999")) + 
    theme(panel.background = element_blank()) + 
    theme(text = element_text(size = 10)) + 
    geom_text(aes(label = protein_count), size = 3, hjust = -0.5) 

我想do是通過它們的Class標識符面向組,但是保持y軸的結構。我在這方面的嘗試產生了一些相當醜陋的情節,似乎在每個方面重複y軸上的標籤。

enter image description here

+0

這些類,你下載他們在哪? –

回答

1

facet_wrap有,你可以用一個參數尺度。秤=「free_y」(也可能是「free_x」如果你做了coord_flip(),使該地塊)應該做的伎倆 - http://docs.ggplot2.org/0.9.3.1/facet_wrap.html

「免費」的因子變量的情況下是指未觀測值在類別內不顯示在軸上。

使用此與空間=「free_x」 /「free_y」一起使刻度在所有方面是相同的(以使類別與更少或更多的分類並不是縮小/放大

編輯:空間沒有爲facet_wrap實現,但你可能能夠實現你想要的與facet_grid

+0

好吧,這解釋了縮放更好的我。添加:+ facet_wrap(Class〜。,scales =「free_x」,space =「free_x」)但是這給了我以下錯誤:facet_wrap(Class〜。,scales =「free_x」,space =「free_x」) : 未使用參數(空格=「free_x」) – hesaguy

+0

我只記得我認爲空間參數只適用於facet_grid。我認爲通常你可以讓facet_grid的功能類似於facet_wrap(不是現在R的前面來試用它)。 – daj