[R] Problem with data frame when using xYplot?

Sander Oom slist at oomvanlieshout.net
Fri May 13 19:41:51 CEST 2005


Sorry Deepayan, I forgot that the code moved on while you send your 
reply. Below the simplified version using your suggestion and this time 
based on the generic data used in the xYplot manual!

Maybe this example can be included in the manual, so next time people 
will find the answer there. Or better still, you could provide a high 
level function in 'lattice'. ;-)

dfr <- expand.grid(month=1:12, continent=c('Europe','USA'),
                    sex=c('female','male'))
set.seed(1)
dfr$y <- dfr$month/10 + 1*(dfr$sex=='female') +
   2*(dfr$continent=='Europe') + runif(48,-.15,.15)
dfr
dfs <- summarize(dfr$y, llist(dfr$continent,dfr$sex),
   smean.cl.normal)
labs <- unique(dfs$continent)
colnames(dfs) <- list("continent","sex","y","Lower","Upper")
dfs$sexnum <- unclass(dfs$sex)
dfs
xYplot(Cbind(y,Lower,Upper) ~ sexnum|continent, data=dfs, nx=FALSE,
   xlim=levels(dfs$sex),
   ylim=c(min(dfs$Lower)-1,max(dfs$Upper)+1),
   )

dfs$xvar <- rep(1:2, each=2)+rep(c(-0.1,0.1), 2)
dfs
sp <- list(superpose.symbol = list(pch = c(16,1), cex = 1),
           superpose.line = list(col = "grey", lty = 1))
xYplot(Cbind(y,Lower,Upper) ~ xvar, groups=sex,  data=dfs,
   xlim= levels(dfs$continent),
   ylim= c(min(dfs$Lower)-1,max(dfs$Upper)+1),
   xlab="Continent",
   panel=function(x, y, type, ...) {
     panel.xYplot(x, y, type="p",...)
     lpoints(x, y, pch=16, col="white", cex=2)
     panel.superpose(x, y, type="p", ...)
   },
   par.settings= sp,
   auto.key= list(columns=1, x=0.7, y=0.8, corner = c(0,0))
   )


Deepayan Sarkar wrote:
> On Friday 13 May 2005 10:36 am, Sander Oom wrote:
>>Hi Deepayan!
>>
>>Deepayan Sarkar wrote:
>>>On Friday 13 May 2005 08:07 am, Sander Oom wrote:
>>>>An off list response from Mat Soukop (thanks Mat!!) provides an even
>>>>more elegant solution (see code below)! I have included the original
>>>>code, so people can decide whether to plot in a single panel or in
>>>>multiple panels. Now we have a fully functional workaround to get
>>>>plotmeans{gplots} for multiple factors using lattice! Great!
>>>Just out of curiousity, does replacing the 'xlim' and 'scales' arguments
>>>above by
>>>
>>>xlim = levels(tmp$Position)
>>>
>>>do the same thing? It should with xyplot (which also allows the x
>>>variable to be a factor), but xYplot may be bypassing that.
>>You mean: xlim = levels(tmp$AltGeo)....yes it does!? 
> 
> No, I meant exactly what I wrote, and my comment followed this piece of code 
> (which you have deleted from your reply):
> 
> ---------
> tmp$PosNum <- unclass(tmp$Position)
> tmp
> (labs <- unique(tmp$Position))
> # plot factor levels in seperate panels
> xYplot(Cbind(Sodium,Lower,Upper) ~ PosNum|AltGeo, data=tmp, nx=FALSE,
>    xlim=c(0.5,2.5),
>    ylim=c(min(tmp$Lower)-1,max(tmp$Upper)+1),
>    scales = list(x = list(at=seq(1, 2, by=1), labels = labs)),
>    xlab="Position", ylab="Sodium"
>    )
> ----------
> 
>>No clue how one would ever get comfortable with all these options!
> 
> By reading the manual, of course :-)
> 
> Deepayan
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
--------------------------------------------
Dr. Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)      +27 (0)11 717 64 04
Tel (home)      +27 (0)18 297 44 51
Fax             +27 (0)18 299 24 64
Email   sander at oomvanlieshout.net
Web     www.oomvanlieshout.net/sander




More information about the R-help mailing list