добро пожаловать
Вид работ тм, я не понимаю, почему 8 цилиндров ломается
library(tidyverse)
outlier_range <- function(x) {
first_quantile <- quantile(x,0.25)
third_quantile <- quantile(x,0.75)
iqr <- IQR(x)
outlier_lower <- max(min(x), first_quantile - 1.5 * iqr)
outlier_higher <- min(max(x), third_quantile + 1.5 * iqr)
return(c(outlier_lower, outlier_higher))
}
ggplot(mtcars) +
aes(x=factor(cyl), y=mpg, fill=factor(cyl)) +
geom_boxplot(width=0.6) +
theme_bw() +
stat_summary(geom="text", fun.y=outlier_range,
aes(label=sprintf("%1.1f", ..y..), color=factor(cyl)),
position=position_nudge(x=0.33), size=3.5)
Пигбинг на @Axeman:
ggplot(mtcars, aes(x=factor(cyl), y=mpg, fill=factor(cyl))) +
geom_boxplot(width=0.6) +
stat_summary(
aes(label=sprintf("%1.1f", ..y..), color=factor(cyl)),
geom="text",
fun.y = function(y) boxplot.stats(y)$stats[c(1,5)],
position=position_nudge(x=0.33),
size=3.5) +
theme_bw()