简体   繁体   中英

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.

The expected plot was shown in the minitab link:

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/

points() does not work with stripchart. So use stripchart() with the option 'add=TRUE'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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