[R] color in xyplot

David Winsemius dwinsemius at comcast.net
Sat Jan 12 06:35:31 CET 2013


On Jan 11, 2013, at 8:38 PM, Elaine Kuo wrote:

> Hello
>
> I want to draw a xyplot.
> Its dots will have three colors: red for meat, green for vegetable,  
> and
> blue for both.
>
> I used the code below but could not make the dot in the same group  
> show the
> same color.
> Please kindly advise how to modify it.

I'm rather amazed you got anything. You are using base graphics  
arguments with a lattice function. There is some overlap but there are  
special functions like `trellis.par.set` and `trellis.par.get`.

Please read :

?lattice

Then read:

  ?xyplot

You need a lot of mental rearrangements to convert from base graphics  
to lattice graphics.

-- 
David.


> Thank you.
>
> code
>
> library (lattice)
> diet.code <- c("Herbivore", "Omnivore", "Carnivore")
>    Diet.colors <- c("forestgreen", "darkblue","red2")
>    levels(dataN$Diet) <- diet.code
>
>  # graph
>    par(mai=c(1.03,1.03,0.4,0.4))
>    par(new=T)
>
>    xyplot(GE_distance~Diet, data=dataN,
>    xlab=list("Diet  of  Breeding  Ground", cex = 1.4),
>    ylab=list("Migration  Distance",cex = 1.4),
>    xaxt="n",
>    yaxt="n",type="p",
>    lwd=1.5,
>    cex.lab=1.4, cex.axis=1.2,
>    font.axis=2,
>    cex=1.5,
>    las=1,
>    bty="l",
>    col=rep(Diet.colors))
>
> 	[[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.

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list