[R] axis colors in pairs plot

Anne York york at zipcon.net
Fri Apr 8 14:53:28 CEST 2005


Thanks Bill and Deepayan for the panel function idea. 

Somehow I've always associated the panel
functions with lattice -- not sure why, but thanks for
pointing out their more universal applicability.

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")[ unclass(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 >




More information about the R-help mailing list