使用geom_jitter和geom_boxplot在g中的ggplot2中控制点颜色 [英] controlling point colors with geom_jitter and geom_boxplot in ggplot2 in R

查看:1421
本文介绍了使用geom_jitter和geom_boxplot在g中的ggplot2中控制点颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ggplot2中添加了以下boxplot,我添加了绘制点数 geom_jitter

  

我根据 factor(cyl)这很好。但是,有些点仍然显示为黑色。这些是什么?这些是箱柜的特例吗?如果是这样,这很奇怪,因为它们中的一些距离颜色点(不是异常值)的中位数还差得远,但也许这是由 geom_jitter 的随机性所解释的。



有人可以解释一下,如果这是正确的解释,并且如果我使用 geom_jitter ?谢谢。

解决方案

黑点是boxplot的异常值。



仅绘制箱形图可以看出。

  ggplot(mtcars,aes(cyl,mpg))+ 
geom_boxplot(aes(fill = as.factor(如果设置outlier.size = 0,则可以执行获取以下操作的任务:获取更多的数据摆脱异常点。你也可以改变颜色。查看?geom_boxplot 获取更多详情。

  ggplot(mtcars,aes (cyl,mpg))+ 
geom_boxplot(aes(fill = as.factor(cyl)),outlier.size = 0)+
geom_jitter(color = factor(cyl))


I have the following boxplot in ggplot2 to which I add the points plotted with geom_jitter:

p <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot(aes(colour=factor(cyl))) + geom_jitter(aes(color=factor(cyl)))

I colored the individual points according to factor(cyl) which works great. However, some points still appear as black. What are these? are these the outlier to the boxplots? If so, it's strange since some of them are just as far from median as the colored points (which are not outliers), but perhaps that is explained by the randomness of geom_jitter?

can someone please explain if that's the correct explanation, and also, how can I make the outliers go away if I use geom_jitter? thanks.

解决方案

The black point is the outlier of the boxplot.

Plotting just the box plot you can see that.

ggplot(mtcars, aes(cyl, mpg)) + 
   geom_boxplot(aes(fill=as.factor(cyl)), outlier.size = 0) 

Setting outlier.size = 0 does the job of getting rid of the outlier dot. You can change colours also. Check out ?geom_boxplot for more details.

ggplot(mtcars, aes(cyl, mpg)) + 
   geom_boxplot(aes(fill=as.factor(cyl)), outlier.size = 0) +
   geom_jitter(color=factor(cyl))

这篇关于使用geom_jitter和geom_boxplot在g中的ggplot2中控制点颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆