简体   繁体   English

R中某些点的条件着色的散点图

[英]Scatter plot with conditional coloring of certain points in R

I'm plotting two pieces of data that I care about, medv and lstat . 我正在绘制我关心的两个数据, medvlstat

I have plotted these two already using boxplots, they are called lstatBox and medvBox . 我已经使用盒图绘制了这两个图,它们分别称为lstatBoxmedvBox The reason I have done this is because I want access to the outliers of these two sets of data. 之所以这样做,是因为我想访问这两套数据的异常值。

Accessing the outlier values is done as such... 这样就可以访问异常值了...

>lstatBox$out
[1] 34.77 34.37 34.41 34.02 36.98 37.97 

>medvBox$out    
[1] 50.0 43.1 39.8 50.0 43.5 50.0 50.0 50.0 46.7 50.0 48.3 50.0 50.0 50.0 48.5 42.3 37.6 37.9 50.0 41.7 41.3 50.0 50.0 46.0
[25] 48.8 50.0 38.7 50.0 45.4 37.2 44.0 43.8 37.3 42.8 50.0 44.8 50.0

I can currently make a scatterplot just by doing this.... 我现在可以通过执行此操作来绘制散点图。

plot(medv,lstat)

BUT, i would like the outlier values for each class to be a different color. 但是,我希望每个类别的异常值是不同的颜色。 Is there a simple way to do this? 有没有简单的方法可以做到这一点?

You could create an array of outlier colors: 您可以创建一组异常颜色:

outlier.colors <- (medv %in% medvBox$out)*1 + (lstat %in% lstatBox$out)*2
outlier.colors <- outlier.colors + 1

plot(medv, lstat, col=outlier.colors)

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

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