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%。因此,它们应该等于geom_violin
在draw_quantiles = c(0.25, 0.5, 0.75)
参数中绘制的0.25 / 0.5 / 0.75分位数。
中位数和50%分位数是相符的。然而,0.25和0.75分位数都不符合箱线图的盒子端点(请参见图中特别是 'virginica' 面板)。
参考文献:
geom_boxplot
文档提到“上边缘,75%分位数”,而geom_violin
文档直接称之为“draw_quantiles”。这让用户认为他们正在处理相同的统计数据,但实际上两者是不同的。 - pat-s