[英]geom_boxplot: replace the lines between the IQR and the whiskers by a second rectangle
Is there a way in ggplot2::geom_boxplot()
to replace the lines between the IQR and the whiskers using a second rectangle? ggplot2::geom_boxplot()
中是否有办法使用第二个矩形替换 IQR 和胡须之间的线? Here is an example of the visual I am trying to achieve:这是我试图实现的视觉效果示例:
source: Hydroclimatic Atlas of Southern Québec, https://www.cehq.gouv.qc.ca/atlas-hydroclimatique/Hydraulicite/Qmoy.htm .来源:魁北克南部水文气候地图集, https://www.cehq.gouv.qc.ca/atlas-hydroclimatique/Hydraulicite/Qmoy.htm 。 (click on a river)
(点击一条河流)
I found how to override the quantiles position of geom_stats()
using:我发现如何使用以下方法覆盖
geom_stats()
的分位数 position:
environment(ggplot2::StatBoxplot$compute_group)$f
Full explanation of this code can be found here: https://coderedirect.com/questions/468264/override-lower-upper-etc-in-boxplot-while-grouping可以在此处找到此代码的完整说明: https://coderedirect.com/questions/468264/override-lower-upper-etc-in-boxplot-while-grouping
It works to draw, for instance, a 95% - 50% - 5% box instead of the classic 75% - 50% - 25% visual, but nothing about how the quantiles are drawn on the graph.例如,它可以绘制一个 95% - 50% - 5% 的框,而不是经典的 75% - 50% - 25% 视觉效果,但没有关于如何在图表上绘制分位数。
Thanks for your thoughts on this:)感谢您对此的想法:)
Perhaps you can use geom_crossbar
.也许您可以使用
geom_crossbar
。 Here's an example using the iris data:这是一个使用 iris 数据的示例:
x = boxplot(Sepal.Length ~ Species, data=iris, plot=FALSE)$stats
x = as.data.frame(t(x))
x$species = unique(iris$Species)
# V1 V2 V3 V4 V5 species
# 1 4.3 4.8 5.0 5.2 5.8 setosa
# 2 4.9 5.6 5.9 6.3 7.0 versicolor
# 3 5.6 6.2 6.5 6.9 7.9 virginica
ggplot(x, aes(species, V3)) +
geom_crossbar(aes(ymin=V1,ymax=V5, fill=species), alpha=0.5) +
geom_crossbar(aes(ymin=V2,ymax=V4, fill=species))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.