1

I tried the following method from Outliers for boxplot and it worked well for me:

bar <- boxplot(foo,plot=FALSE)
boxplot(foo,outline=FALSE,ylim=c(min(c(bar$stats,bar$out)),max(c(bar$stats,bar$out))))
points(jitter(rep(1, length(bar$out))), bar$out)

What I need to do is use it with the boxplot parameter horizontal = TRUE. My boxplot does work horizontally but the jittered outliers are absent.

Any suggestions as to how to make this work? Thanks in advance.

2 Answers2

0

You just need to change the x and y argument for points(). Note also how I simplified ylim.

set.seed(12345)
foo <- rnorm(1000)
bar <- boxplot(foo, plot = FALSE)
boxplot(foo, outline = FALSE,
        ylim = range(foo),
        horizontal = TRUE)
points(bar$out, jitter(rep(1, length(bar$out))))
hplieninger
  • 3,214
  • 27
  • 32
0

In the multigroup setting, the following works:

p <- boxplot(
    Sepal.Width ~ Species,
    data = iris,
    range = 0.5, # Just to get more outliers to show
    outline = FALSE,
    ylim = range(iris$Sepal.Width)
)
points(jitter(p$group, 0.1), p$out)

Created on 2022-02-14 by the reprex package (v2.0.1)

Note the use of p$group to get the x-coordinate of the outliers (rather than rep as in previous answers).

MSR
  • 2,731
  • 1
  • 14
  • 24