Skip to content
Prev 277471 / 398506 Next

points() colored by value

Hi Chris,
On Tue, Nov 15, 2011 at 1:47 PM, Chris82 <rubenbauar at gmx.de> wrote:
In the general sense:
plot(x, y, col=rainbow(length(unique(z)))[as.factor(z)])

converting z to a factor to use as an index is just a quick way to
convert z to sequential values 1,2,3,4 rather than 2,3,4,9 and to
ensure that multiple and unsorted values use the correct color. If z
contains only sequential values, that bit is unnecessary.

I like RColorBrewer for things like this, rather than rainbow, but it
depends on what you're trying to do.

Sarah