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

标签 r plot 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")

但是,我无法弄清楚如何绘制指定条形顶部和底部的类似图。
例如使用下面的数据
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/

相关文章:

r - ggplot2:为没有重叠的组绘制误差线

岭图 : sort by value/rank

mysql - 在 R for Windows 中使用 MySQL

r - 使用了哪个 plot()?

r - 如何在ggplot facet wrap标签中使用不同的字体大小?

r - 如何计算列中每个类别的份额?

sql - 使用 sqldf 的 NA 值

用另一个栅格中的值替换栅格中的值

r - CairoPNG 增加了图边距之外的文本大小

r - 如何在 R 中绘制 CostSensitiveClassifier 树?