Using the code zankuralt posted below and optimise it for faceting you can try:dat %>% gather(key, value, 1:6) %>% mutate(loc = factor(loc, levels = c("abro", "dome")), type = factor(type), key = factor(key)) %>% mutate(type2=as.numeric(type)) %>% group_by(type, loc, key) %>% mutate(d_ymin = min(value), d_ymax = max(value), d_lower = quantile(value, 0.25), d_middle = median(value), d_upper = quantile(value, 0.75)) %>% ggplot() + geom_boxplot(aes(x = type2 - 0.2, ymin = d_lower, ymax = d_upper, lower = d_lower, middle = d_middle, upper = d_upper, width = 2 * 0.2, fill = key), stat = "identity") + geom_jitter(aes(x = type2 + 0.2, y = value, color = key), width = 0.2 - 0.25 * 0.2, height = 0)+ # vertical segment geom_segment(aes(x = type2, y = d_ymin, xend = type2, yend = d_ymax)) + # top horizontal segment geom_segment(aes(x = type2 - 0.1, y = d_ymax, xend = type2, yend = d_ymax)) + # top vertical segment geom_segment(aes(x = type2 - 0.1, y = d_ymin, xend = type2, yend = d_ymin)) + # have to manually add in the x scale because we made everything numeric # to do the shifting scale_x_continuous(breaks = c(1,2), labels = c("big","small"))+ facet_grid(loc ~ key) 这篇关于如何绘制混合箱形图:另一个箱形图上有抖动点的另一个箱形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 02:59