The following is a reproducible solution that uses dplyr and the dplyr built-in mtcars .
Walking through the code: first create an is_outlier function that will return boolean TRUE/FALSE if the value passed to it is a throw. Then we do the “analysis / verification” and build the data - first we group_by our variable ( cyl in this example, in this example, it will be PortugesOutcome ), and we will add the outlier variable to the mutate call (if the drat variable is outlier [note that this corresponds to RatioPort2Dutch in your example], we will pass the drat value, otherwise we will return NA so that the value does not have a graph). Finally, we construct the results and construct the text values through geom_text and an aesthetic label equal to our new variable; in addition, we compensate for the text (move it to the right) with hjust so that we can see the values next to the outling points, and not on top of them.
library(dplyr) library(ggplot2) is_outlier <- function(x) { return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x)) } mtcars %>% group_by(cyl) %>% mutate(outlier = ifelse(is_outlier(drat), drat, as.numeric(NA))) %>% ggplot(., aes(x = factor(cyl), y = drat)) + geom_boxplot() + geom_text(aes(label = outlier), na.rm = TRUE, hjust = -0.3)

Jasonaizkalns
source share