R - 如何使颜色渐变颜色更加不同

时间:2016-08-12 18:25:22

标签: r plot colors

我在下面的示例中使用颜色作为第三维。

layout(matrix(1:2, ncol = 2), width = c(5,1),height = c(1,1))
#rgPal = colorRampPalette(c('red','green')) 
col.jet = function(x, alpha=1) {rev(rainbow(x,start=5/6,end=4/6,alpha=alpha))}
rstc = rstc[order(rstc$efet),]
#rstc$cor = rgPal(nrow(rstc))[as.numeric(cut(rstc$efet,breaks = nrow(rstc)))]
rstc$cor = col.jet(100)[seq(1,85,12)]
par(mai = c(1,1,.3,.6)) 
plot(rstc$sens,rstc$prec, pch=15,col=rstc$cor)
text(rstc$sens-.001,rstc$prec, rstc$cp,cex=.5)
par(mai = c(1,0,.3,0))
legend_image = as.raster(matrix(rstc$cor[order(rstc$cor, decreasing = T )] , ncol=1))
plot(c(0,1),c(0,1),type = 'n', axes = F, xlab = '', ylab = '')
text(x=0.2, y =(1:8)/8, labels = rstc$efet, cex = .5)
rasterImage(legend_image,  xleft=0.3, ybottom=0, xright=.6, ytop=1)

数据

> rstc
      cp        qx   efet  prec  sens   acu    p_pred       cor
8 0.0100 0.2785192  5.772 0.340 0.223 0.664 0.6559006 #0000FFFF
1 0.0020 0.2075472  7.838 0.337 0.337 0.632 0.9997516 #009BFFFF
7 0.0080 0.2901235 10.586 0.346 0.342 0.638 0.9874534 #00FFC9FF
6 0.0075 0.2915392 11.536 0.349 0.345 0.640 0.9877019 #00FF2EFF
2 0.0030 0.2084507 11.961 0.350 0.349 0.640 0.9967702 #6CFF00FF
5 0.0060 0.2905473 12.437 0.352 0.347 0.642 0.9839752 #FFF700FF
4 0.0050 0.2777778 12.957 0.353 0.353 0.641 0.9997516 #FF5D00FF
3 0.0040 0.2504440 13.201 0.354 0.351 0.642 0.9940373 #FF003EFF

但主要在上层的颜色太相似了 根据@jgadoury的建议,尝试使颜色更加不同,我将其修改为使用喷射色标。这将是一个更好的解决方案,但由于某种原因,颜色不符合价值!例如,cp=0.004应为顶部颜色,刻度中为黄色,但为红色! 我犯了错误吗? see plot here

0 个答案:

没有答案