【发布时间】:2020-08-15 21:50:51
【问题描述】:
我一直在尝试在以下数据帧 (df) 中为高于定义阈值的特定 bin 着色
df <- read.table("https://pastebin.com/raw/3En2GWG6", header=T)
我一直在关注这个例子 (Change colour of specific histogram bins in R),但我似乎无法让他们的建议适应我的数据,所以我想在 stackoverflow 上问你
我希望所有值高于 0.100 的 bin 都为“红色”,其余的要么没有颜色,要么只是黑色(我定义了黑色,但我更喜欢没有颜色)
这是我尝试过的:
col<-(df$consumption>=0.100)
table(col) # I can see 40 points above 100, the rest below
col[which(col=="TRUE")] <- "firebrick1"
col[which(col=="FALSE")] <- "black"
hist(df$consumption, breaks = 1000, xlim = c(0,0.2), col=col,xlab= "Consumption [MG]")
但是,整个图表都是红色的,这没有意义..?
换句话说,我希望下一行右侧的 anything 为红色
hist(df$consumption, breaks = 1000, xlim = c(0,0.2),xlab= "Consumption [MG]")
abline(v=c(.100), col=c("red"),lty=c(1), lwd=c(5))
【问题讨论】: