【问题标题】:shade section of bin in histogram in rr中直方图中bin的阴影部分
【发布时间】:2018-02-01 14:44:57
【问题描述】:

我有一个直方图,将 data 中的值绘制在 5 个 bin 中。最后一个 bin 包含 95-100 范围内的值。我想将这个 bin 中值为 100 的数据点的数量涂成红色。

data<-c(78,100,90,100,96,100,100,82,95,99,100,97,79,99,100,77,79,100,95,100,100,100,82,77,82)
hist(data, xlab="Score",breaks=c(75,80,85,90,95,100),ylab = "Frequency", main = paste("Score Distribution"), cex.main = 1.55, cex.lab = 1, freq = TRUE)

当前图像

所需图像

【问题讨论】:

  • 听起来你应该使用条形图而不是直方图。而且您已标记 ggplot2 但您只是在示例中使用基本图形。用什么重要吗?
  • 我愿意使用条形图格式,只要它看起来像直方图。我添加了 ggplot2,因为我知道 ggplot2 在格式化方面具有更大的灵活性。

标签: r plot formatting histogram


【解决方案1】:

您可以使用add=T

data<-c(78,100,90,100,96,100,100,82,95,99,100,97,79,99,100,77,79,100,95,100,100,100,82,77,82)
hist(data, xlab="Score",breaks=c(75,80,85,90,95,100),ylab = "Frequency", main = paste("Score Distribution"), cex.main = 1.55, cex.lab = 1, freq = TRUE)

newdata <- data[data == 100]

hist(newdata, xlab="Score",breaks=c(75,80,85,90,95,100),ylab = "Frequency", main = paste("Score Distribution"), cex.main = 1.55, cex.lab = 1, freq = TRUE, col="red", add=T)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    • 2021-03-01
    • 2014-03-18
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多