2013-04-02 46 views
0

我想繪製使用ggplot2 boxplot。樣本數據是這樣的。ggplot2 boxplot

> sampe

count genotype 
71  mt 
50  mt 
71  mt 
95  wt 
60  mt 
63  mt 
75  mt 
82  wt 
93  wt 
87  wt 
61  mt 
102  wt 
60  mt 
78  wt 
78  wt 
87  wt 
84  wt 
104  wt 
81  wt 
85  mt 


> qplot(factor(genotype),count,data=sampe,geom="boxplot") 

上面的命令產生的情節是這樣的: enter image description here

什麼是錯在這裏?爲什麼它這樣陰謀?即使這下面的代碼產生相同的輸出。

ggplot(sampe,aes(x=factor(genotype),y=count))+geom_boxplot() 
+0

您的代碼適用於我。你使用的是哪個版本:packageDescription(「ggplot2」)$ Version' - 最新版本是0.9.3.1 – csgillespie

+1

它在這裏運行得很好。什麼給'class(s​​ampe $ count)'?我猜這是一個「因素」? – juba

+8

看來您的計數值在您的數據中存儲爲因子,這是我可以重現您的情節的唯一方法。 –

回答

4

好的..我會回答我自己的問題。按照建議計數值被存儲爲因子。將它們轉換爲數字的方法訣竅

qplot(factor(genotype),as.numeric(count),data=sampe,geom="boxplot") 

謝謝大家的建議。

0

我認爲你的問題在於你的Y軸實際上並不算數,R理解爲一個變量。 其實你只需要按照基因型分組數據,而不是ggplot2。

df %>% group_by(genotype) 
ggplot(df) + 
    geom_boxplot(mapping = aes(x=genotype, y = count))