[R] xyplot colour points and layout

Duncan Mackay dulcalma at bigpond.com
Fri Aug 28 01:03:16 CEST 2015


Hi 

Following on from Davids reply you can do the following if you want a key or
legend.
By putting the colour scheme in par.settings the "local" equivalent of
setting trellis.par.set() for that plot
you can get things right for the key without having to have add arguments to
key

  culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")

  xyplot(Abun~Date1|Station, data=Raw,
        groups = culr,
        par.settings = list(strip.background = list(col = "transparent"),
                            superpose.symbol = list(cex = rep(2, 2),
                                                    col=c("grey","black"),
                                                    pch = rep(16,2))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Abundance",cex=1.5),
        auto.key = T)

see 
names(trellis.par.get())
for a list of the settings

Regards

Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au


-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Christine
Lee via R-help
Sent: Thursday, 27 August 2015 13:41
To: r-help at r-project.org
Subject: [R] xyplot colour points and layout

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'))


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.



More information about the R-help mailing list