Expanding on dangerstat's answer, here is a little function that will automatically find which bin contains the value that you want to highlight:
highlight <- function(x, value, col.value, col=NA, ...){
hst <- hist(x, ...)
idx <- findInterval(value, hst$breaks)
cols <- rep(col, length(hst$counts))
cols[idx] <- col.value
hist(x, col=cols, ...)
}
Now
x <- rnorm(100)
highlight(x, 1.2, "red")
will highlight the bin with 1.2 in it in red.
x = rnorm(100)
hist(x,br=10,col=c(rep(0,9),1))
Clearly this will color the last column so tweak the col= bit for your needs
Thanks
dangerstat
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.