如何仅基于min和max创建箱形图

Luc*_*ini 3 plot r ggplot2

在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")
Run Code Online (Sandbox Code Playgroud)

但是,我无法弄清楚如何制作一个类似的情节,指出了条形的顶部和底部.例如,使用下面的数据

df <- read.table(text = " id  min  max 
    Sp1     8.5          13.2     
 Sp2     11.7          14.5     
 Sp3     14.7          17.7     ", header=TRUE)
Run Code Online (Sandbox Code Playgroud)

我们会得到一个非常类似的情节: 在此输入图像描述

有什么建议?

Sve*_*ein 5

You can use geom_crossbar:

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

enter image description here