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]]
Hi, Are your variable numerical? If so, you can do what you want by just define the color as the variable (col = variable3). Colors in R can be defined by numbers, so each number will corresponds to one color. In example: plot( iris[, 1], iris[, 2], col = iris[,3]) Regards 2009/3/18 Josh <tejalonline@gmail.com>> 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@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. >[[alternative HTML version deleted]]
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. > >Hi Josh, Have a look at color.scale in the plotrix package. This function converts numeric values into colors along an arbitrary color dimension. Jim
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