R:根据数据帧的值为矩形着色
首先是对我要找的东西的解释,然后是一些可复制的简单代码 在我的例子中,我有一个简单的绘图,没有任何线条,只有10个矩形。 我的目标是将10个矩形涂成绿色、红色或黄色。 矩形的颜色由预装数据集randu的x列的最后10次观察值得出R:根据数据帧的值为矩形着色,r,plot,colors,rect,R,Plot,Colors,Rect,首先是对我要找的东西的解释,然后是一些可复制的简单代码 在我的例子中,我有一个简单的绘图,没有任何线条,只有10个矩形。 我的目标是将10个矩形涂成绿色、红色或黄色。 矩形的颜色由预装数据集randu的x列的最后10次观察值得出 如果该值大于0.7,则矩形应为红色 如果该值>=0.7且,则应能实现此目的。代码不使用矢量farben,而是根据您列出的标准直接指定颜色: plot(c(0, 20), c(0, 40), type= "n", xlab = "", ylab = "") for (i
farben
,而是根据您列出的标准直接指定颜色:
plot(c(0, 20), c(0, 40), type= "n", xlab = "", ylab = "")
for (i in 0:10) {
randu_value <- tail(randu[, "x"], 11)[i+1]
if(randu_value > 0.7) color <- "#FF0000"
if(randu_value <= 0.7 & randu_value >= 0.5) color <- "#00FF00"
if(randu_value < 0.5) color <- "#FFFF00"
rect(i, 0, (i+1), 5, border = "black", col=color)
}
plot(c(0,20),c(0,40),type=“n”,xlab=“”,ylab=“”)
因为(我在0:10){
randu_值0.7)颜色
plot(c(0, 20), c(0, 40), type= "n", xlab = "", ylab = "")
for (i in 0:10) {
randu_value <- tail(randu[, "x"], 11)[i+1]
if(randu_value > 0.7) color <- "#FF0000"
if(randu_value <= 0.7 & randu_value >= 0.5) color <- "#00FF00"
if(randu_value < 0.5) color <- "#FFFF00"
rect(i, 0, (i+1), 5, border = "black", col=color)
}