require(ggplot2)
require(cowplot)
d = iris
ggplot2::ggplot(d, aes(factor(0), Sepal.Length)) +
geom_violin(fill="black", alpha=0.2, draw_quantiles = c(0.25, 0.5, 0.75)
, colour = "red", size = 1.5) +
stat_boxplot(geom ='errorbar', width = 0.1)+
geom_boxplot(width = 0.2)+
facet_grid(. ~ Species, scales = "free_x") +
xlab("") +
ylab (expression(paste("Value"))) +
coord_cartesian(ylim = c(3.5,9.5)) +
scale_y_continuous(breaks = seq(4, 9, 1)) +
theme(axis.text.x=element_blank(),
axis.text.y = element_text(size = rel(1.5)),
axis.ticks.x = element_blank(),
strip.background=element_rect(fill="black"),
strip.text=element_text(color="white", face="bold"),
legend.position = "none") +
background_grid(major = "xy", minor = "none")
据我所知,以箱线图结尾的方框分别代表 25% 和 75% 的分位数,中位数 = 50%。所以它们应该等于参数中绘制的 0.25/0.5/0.75 分geom_violin
位数draw_quantiles = c(0.25, 0.5, 0.75)
。
中位数和 50% 分位数拟合。但是,0.25 和 0.75 分位数都不适合箱线图的箱端(见图,尤其是 'virginica' 刻面)。
参考: