简体   繁体   English

R:设置条形图中单个数据点的颜色

[英]R: Setting the color for an individual data point in stripchart

I have trouble in setting the color of an outlier in a stripchart.我无法在条形图中设置异常值的颜色。 I tried two method, but neither worked.我尝试了两种方法,但都没有奏效。

Here is the code:这是代码:

x = rnorm(30)
x[20]=10

# 1
stripchart(x,main='Outlier Plot',xlab='x', pch=20, col=ifelse(x==10, 'red', 'blue'))

# 2
cols = rep('blue',length(x))
cols[which(x==10)]='red'
stripchart(x,main='Outlier Plot',xlab='x', pch=20, col=cols)

The colors are all blue with no change. colors 都是蓝色的,没有变化。

The expected plot was shown in the minitab link:预期的 plot 显示在 minitab 链接中:

https://support.minitab.com/en-us/minitab/20/help-and-how-to/statistics/basic-statistics/how-to/outlier-test/perform-the-analysis/select-the-graph/ https://support.minitab.com/en-us/minitab/20/help-and-how-to/statistics/basic-statistics/how-to/outlier-test/perform-the-analysis/select-the-图形/

points() does not work with stripchart. points() 不适用于条形图。 So use stripchart() with the option 'add=TRUE'所以使用带有选项'add = TRUE'的stripchart()

    stripchart(x,pch=20,col='blue')
    stripchart(x[11],col='red',pch=20, add=TRUE)

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

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