[R] xyplot colour points and layout

David Winsemius dwinsemius at comcast.net
Thu Aug 27 07:38:24 CEST 2015


On Aug 26, 2015, at 8:41 PM, Christine Lee via R-help wrote:

> Dear All,
> 
> I have tried to plot graphs of one row of four figures for each station.  In each graph, black points indicate data in the year of 2002, denoted as Y2002, whereas grey points indicate data in the year of 2014, denoted as Y2014.  I ended up with 2x2 plots with all data points in black.  Can anyone find out what has gone wrong by any chance please?
> 
> Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L, 
> 2L, 4L, 12L, 6L, 15L, 14L, 3L, 6L, 1L, 16L, 5L, 11L, 8L, 4L, 
> 10L, 13L, 6L, 1L, 16L, 5L, 11L, 8L, 4L, 10L, 13L, 6L, 1L, 16L, 
> 5L, 11L, 8L, 4L, 10L, 13L, 11L, 8L, 4L, 10L, 13L), .Label = c("1/10", 
> "1/11", "11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", 
> "26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class = "factor"), 
>    Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
>    1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
>    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
>    2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"), 
>    Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
>    2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
>    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
>    3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("E", "F", "H", "I"
>    ), class = "factor"), Abun = c(3.42, 1.33, 3.67, 3.67, 3.92, 
>    2.17, 2.5, 1.67, 6.33, 0.67, 1, 1, 1.33, 2.08, 0, 0, 0.33, 
>    0.08, 0.08, 0, 0.5, 0.17, 0.67, 0.67, 0, 1, 0.58, 1.5, 2.67, 
>    0.67, 1.33, 3, 0.58, 1.17, 1.25, 0.75, 1.25, 1.75, 0.92, 
>    1.5, 0.83, 0.75, 2.33, 0.67, 1.33, 1.58), Date1 = structure(c(16697, 
>    16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768, 
>    16697, 16712, 16739, 16750, 16697, 16709, 16714, 16721, 16737, 
>    16741, 16751, 16765, 16769, 16697, 16709, 16714, 16721, 16737, 
>    16741, 16751, 16765, 16769, 16697, 16709, 16714, 16721, 16737, 
>    16741, 16751, 16765, 16769, 16737, 16741, 16751, 16765, 16769
>    ), class = "Date")), .Names = c("Date", "Year", "Station", 
> "Abun", "Date1"), row.names = c(NA, -46L), class = "data.frame")
> Raw$Date1<-as.Date(Raw$Date,"%d/%m")
> library(lattice)
> par(mfrow=c(1,4))
> culr<-ifelse(Raw$Year=="Y2002","Black","Grey")
> xyplot(Abun~Date1|Station,Raw,type="p",xlab=list("Month",cex=1.5),ylab=list("Abundance",cex=1.5),cex=2,pch=16,col=culr,strip=strip.custom(bg='white'))

Try putting in a groups argument (after adding the group identifier to the dataframe:

 xyplot(Abun~Date1|Station,  groups=culr, col=c("grey","black"),      
        data=Raw, type="p", xlab=list("Month",cex=1.5), ylab=list("Abundance",cex=1.5),
       cex=2, pch=16, strip=strip. custom(bg='white'))


> 
> 
> Many thanks.
> 
> Regards,
> Christine
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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
Alameda, CA, USA



More information about the R-help mailing list