[R] Lattice:can't subset in panel function using other variables
FolkesM at pac.dfo-mpo.gc.ca
Sat Sep 1 01:51:07 CEST 2007
Thanks Deepayan for your response.
The first subset you suggest was just a test for me and not what I
I can't do your second suggested subset action as I wish to plot all the
panel data, but then add a coloured datapoint for just one year (see
I think I have found my problem but don't know how to solve it.
The subscripts of data going into each panel are almost always the same
length, except maybe one or two panels have 1 less datapoint.
I've attached a script that builds a quick dataset and plots what I was
aiming for. It works great. If you then remove one line of data from
the DF (using "df<-df[-1,]" in the script), the plotting goes awry.
Any suggestions about dealing with unequal data lengths for panel
Thanks so much
***********Start of code
#This builds fake dataset
#df<-df[-1,] #<-run this to see problem if panel data are of unequal
print(xyplot(yvar~xvar|week2,data=df,layout = c(4, 5),
strip = strip.custom(strip.names = F, strip.levels = TRUE),
***********End of code
From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com]
Sent: August 31, 2007 2:04 PM
To: Folkes, Michael
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Lattice:can't subset in panel function using other
On 8/30/07, Folkes, Michael <FolkesM at pac.dfo-mpo.gc.ca> wrote:
> I've succeeded doing a subset within the panel function of xyplot - if
I'm subsetting based on either the value of 'x' or 'y' (e.g. below).
However, I wish to subset based on the value of another variable and
colour that one plotted point. It's not working. Either it doesn't
plot the coloured data point, or if I sort the data differently it
colours one datapoint, but the wrong one. I assume this means it's not
getting the right subscripts? Finally I can sort of see the light as
if I remove the conditioning variable (week) and subset before the
xyplot (e.g. week==1) to get just one panel, it plots the correct data
including the correct single red point.
> Where am I erring?
> panel.xyplot(x[y<=40],y[y<=40],type='p',col=2,cex=.5) #
,cex=.5) # <-----sometimes this won't work or it colours wrong
xyplot(yval~xval|week,data=mydata, subset = yval < 40)
xyplot(yval~xval|week,data=mydata, subset = yr==2005)
More information about the R-help