r中直方图中bin的阴影部分

时间:2018-02-01 14:44:57

标签: r plot formatting histogram

我有一个直方图,它将for (unsigned int i = 0; i < lineLength; i++) 中的值绘制在5的容器中。最后一个bin包含的值范围为95-100。我想用红色阴影表示此bin中值为100的数据点数。

data

当前图片

enter image description here 期望的图像

enter image description here

1 个答案:

答案 0 :(得分: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)