possible improvements

Discuss the jamovi platform, possible improvements, etc.
vieira
Posts: 1
Joined: Thu May 13, 2021 9:31 pm

Re: possible improvements

Post by vieira »

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/335 ... plots-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) 
Post Reply