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

341 views Asked by At

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/

1

There are 1 answers

0
ppppppppp On

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)