Reputation: 431
I am trying to plot boxplot using ggplot2. sample data is like this.
> 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")
The above command produces plot like this:
what's wrong here?? why is it plotting like this?? Even this below code produces same output.
ggplot(sampe,aes(x=factor(genotype),y=count))+geom_boxplot()
Upvotes: 0
Views: 1643
Reputation: 849
I think your problem is that your Y-axis is not actually count, R understand count as a variable. Actually you only need to group the data by genotype and than do ggplot2.
df %>% group_by(genotype)
ggplot(df) +
geom_boxplot(mapping = aes(x=genotype, y = count))
Upvotes: 0
Reputation: 431
Ok.. I 'll answer my own question. As per the suggestion count values were stored as factor. Converting them to numeric did the trick
qplot(factor(genotype),as.numeric(count),data=sampe,geom="boxplot")
Thank you all for the suggestions.
Upvotes: 5