在 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)
We would get a plot closely resembling this:
![enter image description here](https://i.stack.imgur.com/mRNdE.png)
有什么建议么?
您可以使用geom_crossbar
:
ggplot(df) +
geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
fill = "blue", fatten = 0)
![enter image description here](https://i.stack.imgur.com/nZ2ql.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)