r - fine-grained colour gradient legend -
i have problem when making colour gradient legend. in case data can range 0 1, , differences between values can small, making legend more or less unicolour. there way make gradient more fine-grained?
#dummy data prob <- c(0.24228,0.24330,0.19590,0.28554,0.18260,0.24626,0.21664,0.21598,0.22754,0.19366,0.36778,0.18854,0.48554,0.21922,0.20212,0.25406,0.18744,0.22476,0.17464,0.20828,0.19084,0.21878,0.17642,0.17190,0.31024,0.30492,0.16838,0.22374,0.20550,0.21550,0.19432,0.22890,0.17526,0.16864,0.33064,0.20454,0.19704,0.30926,0.18156,0.26320,0.18686,0.18234,0.17128,0.19186,0.39960,0.23060,0.26152,0.42696,0.25806,0.16712,0.17568,0.28280,0.19872,0.16790,0.28618,0.31684,0.36114,0.32234,0.23386,0.19820,0.21796,0.22628,0.16930,0.16700,0.16364,0.19562,0.19706,0.20404,0.22368,0.39426,0.23390,0.26944,0.22828,0.17430,0.16262,0.16722,0.16362,0.19150,0.39826,0.32130,0.28422,0.16902,0.19758,0.18310,0.17334,0.17308,0.16654,0.20186,0.26402,0.17904,0.20244,0.23508,0.25188,0.36882,0.18062,0.24956,0.20742,0.17328,0.18414,0.19626,0.19368,0.36542,0.23246,0.19910,0.31924,0.35536,0.31374,0.28556,0.29444,0.19620,0.18296,0.17322,0.33390,0.16920,0.30898,0.41456,0.16678,0.48374,0.24966,0.17130,0.42178,0.20878,0.22610,0.17204,0.19620,0.50638) # update - fix prob <- prob[!duplicated(prob)] my.palette <- rev(rgb(prob[order(prob)], 1-prob[order(prob)], 0, maxcolorvalue=1)) image(1, prob[order(prob)], t(seq_along(prob)), col=my.palette, axes=false, main="probability") axis(2)
it seems plotting data rather making legend.
anyway.. problem mismatch between data range , maxcolorvalue. so, can set max...
red <- prob[order(prob)] green <- max(prob)-prob[order(prob)] my.palette <- rev(rgb(red, green, 0, maxcolorvalue=max(prob))) image(1, prob[order(prob)], t(seq_along(prob)), col=my.palette, axes=false, main="probability") axis(2)
..or rescale data better color variations.
scaledprob <- (prob[order(prob)]- min(prob)) / (max(prob) - min(prob)) my.palette <- rev(rgb(scaledprob, 1-scaledprob, 0, maxcolorvalue=1)) image(1, prob[order(prob)], t(scaledprob), col=my.palette, axes=false, main="probability") axis(2)
Comments
Post a Comment