Hi R users, I want to colored points by their value for example: x <- c(1,2,3,4) y <- c(1,2,3,4) z <- c(2,3,4,9) y and x are coordinates z is the value of the coordinates points(x,y,col= rainbow(z)) something like that But haven't found any solution at the moment. Thanks. Chris -- View this message in context: http://r.789695.n4.nabble.com/points-colored-by-value-tp4073640p4073640.html Sent from the R help mailing list archive at Nabble.com.
points() colored by value
3 messages · Chris82, michael.weylandt at gmail.com (R. Michael Weylandt, Sarah Goslee
Try either col=z or col=rainbow(max(z))[z] depending on what color scheme you want. Michael
On Nov 15, 2011, at 1:47 PM, Chris82 <rubenbauar at gmx.de> wrote:
Hi R users, I want to colored points by their value for example: x <- c(1,2,3,4) y <- c(1,2,3,4) z <- c(2,3,4,9) y and x are coordinates z is the value of the coordinates points(x,y,col= rainbow(z)) something like that But haven't found any solution at the moment. Thanks. Chris -- View this message in context: http://r.789695.n4.nabble.com/points-colored-by-value-tp4073640p4073640.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi Chris,
On Tue, Nov 15, 2011 at 1:47 PM, Chris82 <rubenbauar at gmx.de> wrote:
Hi R users, I want to colored points by their value for example: x <- c(1,2,3,4) y <- c(1,2,3,4) z <- c(2,3,4,9) y and x are coordinates z is the value of the coordinates points(x,y,col= rainbow(z))
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
something like that But haven't found any solution at the moment. Thanks. Chris
Sarah Goslee http://www.functionaldiversity.org