2013-04-02 78 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))