[R] 2D plot with colors from 3rd variable?

Paul Hiemstra p.hiemstra at geo.uu.nl
Wed Mar 18 14:03:42 CET 2009


Hi,

Be sure to take a look at the levelplot() function from the lattice 
package. From the documentation of levelplot:

library(lattice)
x <- seq(pi/4, 5 * pi, length.out = 100)
y <- seq(pi/4, 5 * pi, length.out = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid, cuts = 50, scales=list(log="e"), xlab="",
            ylab="", main="Weird Function", sub="with log scales",
            colorkey = FALSE, region = TRUE)

cheers,
Paul

Josh wrote:
> Hi,
> I have three related variables (vectors) and would like to see their
> distribution on a 2D plot of first two variables, having colors proportional
> to the values from third variable. I could have done so by passing 3rd
> variable to the color palette, but this would disrupt the relationship
> information among them.
> I am sure there has to be some way to do it, but I don't know how. Any help
> in this direction will be appreciated.
>
> thanks
> jo
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>   


-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul




More information about the R-help mailing list