简体   繁体   English

GGplot Boxplot与Boxplot

[英]GGplot Boxplot vs boxplot

I am trying to do a boxplot with GGplot and I get only one box when I do a ggplot like 我正在尝试用GGplot做一个boxplot,当我做一个ggplot时我只会得到一个盒子

ggplot(data_frame, aes(x=probs, y=values)) + 
  geom_boxplot(color="red", fill="orange", alpha=0.5)

while I should be getting 3 boxes when I do the normal plot: 当我进行正常绘图时,我应该得到3个盒子:

boxplot(values ~ probs, data = data_frame,
        xlab = "Probabilities", 
        ylab = "Values (1Q, Mean, Median, StdDev, 3Q)", 
        main = "1Q, Mean, Median, StdDev, 3Q", 
        col = c("green","yellow","purple"))

Sample data:
> head(data_frame,20)
   values probs
1  16.000   0.3
2  18.000   0.3
3  18.000   0.3
4   3.550   0.3
5  20.000   0.3
6  27.000   0.5
7  30.000   0.5
8  30.000   0.5
9   3.873   0.5
10 33.000   0.5
11 46.000   0.8
12 48.000   0.8
13 48.000   0.8
14  3.098   0.8
15 50.000   0.8

Any pointers is much appreciated. 非常感谢任何指针。 Thanks! 谢谢!

Geom_boxplot's X axis must be categorical to get it like you want to. Geom_boxplot的X轴必须是分类的,以使其如您所愿。 One solution is to transform "probs" as character: 一种解决方案是将“概率”转换为字符:

ggplot(data_frame, aes(x=as.character(probs), y=values)) + 
  geom_boxplot(color="red", fill="orange", alpha=0.5)

Hopefully this is what you are looking for... 希望这是您要寻找的...

ggplot(df, aes(x=factor(probs), y=values)) + 
    geom_boxplot(color="red", fill="orange", alpha=0.5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM