Re: [R] pairs() uses col argument for axes coloring

From: Anne York <york_at_zipcon.net>
Date: Sat 09 Jul 2005 - 01:20:39 EST

A work-around for this problem was posted on April 7 by Bill Venables and Deepayan Sarkar using a panel function:

Anne
On Thu, 7 Apr 2005, Deepayan Sarkar wrote:

DS > On Thursday 07 April 2005 17:51, Anne York wrote: DS > > The following command produces red axis line in a pairs

DS > > plot:
DS > >
DS > > pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",
DS > > pch = "+", col = c("red", "green3",  "blue")[unclass(iris$Species)])
DS > >
DS > >
DS > > Trying to fool pairs in the following  way  produces 
the
DS > > same plot as above:
DS > >
DS > > pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",pch =
DS > > "+", col = c("black", "red", "green3", "blue")[ 1+
DS > > unclass(iris$Species)])
DS > >
DS > > One very kludgy work-around is to define a new level 1, say
DS > > "foo" in the first row of iris:
DS > >
DS > > iris2=iris
DS > > iris2$Species = as.character(iris2$Species)
DS > > iris2$Species[1]="foo"
DS > > iris2$Species = factor(iris2$Species)
DS > >
DS > > pairs(iris2[1:4], main = "Anderson's Iris Data -- 3
DS > > species", pch = "+",
DS > > col = c( "black","red", "green3","blue")[ 
unclass(iris2$Species)])
DS > >
DS > > However, if any other row is redefined, the red-axis
DS > > persists. For example:
DS > >
DS > > iris2=iris
DS > > iris2$Species = as.character(iris2$Species)
DS > > iris2$Species[3]="foo"
DS > > iris2$Species = factor(iris2$Species)
DS > >
DS > >
DS > > pairs(iris2[1:4], main = "Anderson's Iris Data -- 3
DS > > species", pch = "+",
DS > > col = c( "black","red", "green3","blue")[ nclass(iris2$Species)])
DS > >
DS > > I'd appreciate suggestions for a simpler work-around.
DS > 
DS > One possibility is something along the lines of
DS > 
DS > pairs(iris[1:4], 
DS >       panel = function(...)
DS >           points(..., 
DS >                  col = c("red", "green3", "blue")
DS >                          [unclass(iris$Species)]  ))
DS > 
DS > Deepayan
DS > 
DS >



On Fri, 8 Jul 2005, Olaf Mersmann wrote:

OM > Hi list,
OM > 
OM > not sure if this is the wanted behavior, but running the following code:
OM > 
OM > > version
OM > platform i386-pc-mingw32
OM > arch     i386
OM > os       mingw32
OM > system   i386, mingw32
OM > status
OM > major    2
OM > minor    1.1
OM > year     2005
OM > month    06
OM > day      20         
OM > language R
OM > > n <- 500
OM > > d <- 4
OM > > m <- matrix(runif(n*d, -1, 1), ncol=d)
OM > > c <- hsv(apply(m, 1, function(x) {sum(x*x)/d}), 1, 1)
OM > > pairs(m, col=c)
OM > 
OM > gives me the desired coloring of the points but also colors the axes.
OM > Looking at the source for pairs() suggests, that this is the case
OM > because col is part of the ... argument list which is passed on to
OM > localAxis (and from there to axis). Wouldn't it be more approptiate to
OM > use the same color box() uses to draw the border around each
OM > scatterplot? If yes, should I open a bug for this or how would such a
OM > feature request be handled?
OM > 
OM > -- Olaf Mersmann
OM > 
OM > ______________________________________________
OM > R-help@stat.math.ethz.ch mailing list
OM > https://stat.ethz.ch/mailman/listinfo/r-help
OM > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
OM > 
OM >

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jul 09 01:24:38 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:24 EST