This is my first post, so apologies if this is not the right place to post this. I was also trying to solve the problem of labeling outliers in boxplots. I have hardly any knowledge of R but managed to adapt a piece of code that did the trick for me using Rj Editor taken from https://stackoverflow.com/questions/33524669/labeling-outliers-of-boxplots-in-r. In the below example age and status were the variables I used and would need to be adapted.

- Code: Select all
`library(jmv)`

library(dplyr)

library(ggplot2)

library(tibble)

is_outlier <- function(x) {

return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))

}

dat <- data %>% tibble::rownames_to_column(var="outlier") %>% group_by(status) %>% mutate(is_outlier=ifelse(is_outlier(age), age, as.numeric(NA)))

dat$outlier[which(is.na(dat$is_outlier))] <- as.numeric(NA)

ggplot(dat, aes(y=age, x=factor(status))) + geom_boxplot() + geom_text(aes(label=outlier),na.rm=TRUE,nudge_x=0.1)