gpt4 book ai didi

r - 如何仅基于最小值和最大值创建箱线图

转载 作者:行者123 更新时间:2023-12-01 09:57:58 24 4
gpt4 key购买 nike

在 ggplot 中,我们可以通过指定数据框中具有条形高度的列来创建条形图

library("ggplot2")
library(plyr)
mm <- ddply(mtcars, "cyl", summarise, mmpg = mean(mpg))
ggplot(mm, aes(x = factor(cyl), y = mmpg)) + geom_bar(stat = "identity")

但是,我无法弄清楚如何绘制指定条形顶部和底部的类似图。
例如使用下面的数据
df <- read.table(text = " id  min  max 
Sp1 8.5 13.2
Sp2 11.7 14.5
Sp3 14.7 17.7 ", header=TRUE)

我们会得到一个与此非常相似的情节:
enter image description here

有什么建议?

最佳答案

您可以使用 geom_crossbar :

ggplot(df) +
geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
fill = "blue", fatten = 0)

enter image description here

关于r - 如何仅基于最小值和最大值创建箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21560861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com