[R] not working yet: Re: lattice overlay

Duncan Mackay mackay at northnet.com.au
Fri Jul 29 01:25:10 CEST 2011


At 21:50 28/07/2011, you wrote:
>Hi Dieter and R community:
>
>I tried both of these three versions with ylim as suggested, none work:  I
>am getting only single (pch = 16) not overlayed (pch =3) everytime.
>
>*vs 1*
>
>require(lattice)
>
>xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,
>
>   panel= function(x, y, subscripts) {
>
>panel.xyplot(x, y, pch=16, col = "green4", ylim = c(0, 10))
>
>panel.lmline(x, y, lty=4, col = "green4")
>
>panel.xyplot (iris$Petal.Length [subscripts],
>iris$Petal.Width[subscripts], pch= 3, col = "red")
>
>panel.lmline(iris$Petal.Length [subscripts], iris$Petal.Width
>[subscripts], col = "red")
>
>}, as.table=T, subscripts=T)
>
>
>*vs 2*
>
>require(lattice)
>
>xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,
>
>   panel= function(x, y, subscripts) {
>
>panel.xyplot(x, y, pch=16, col = "green4", ylim = c(0, 10))
>
>panel.lmline(x, y, lty=4, col = "green4")
>
>
>panel.xyplot (iris$Petal.Length [subscripts], iris$Petal.Width[subscripts],
>pch= 3, col = "red", ylim = c(0,10)
>
>  )
>
>panel.lmline(iris$Petal.Length [subscripts], iris$Petal.Width
>[subscripts], col = "red")
>
>}, as.table=T, subscripts=T)
>
>
>
>*vs 3*
>
>require(lattice)
>
>xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,
>
>   panel= function(x, y, subscripts) {
>
>panel.xyplot(x, y, pch=16, col = "green4")
>
>panel.lmline(x, y, lty=4, col = "green4")
>
>
>panel.xyplot (iris$Petal.Length [subscripts], iris$Petal.Width[subscripts],
>pch= 3, col = "red", ylim= c(0,10)
>
>  )
>
>panel.lmline(iris$Petal.Length [subscripts], iris$Petal.Width
>[subscripts], col = "red")
>
>}, as.table=T, subscripts=T)
>
>Help please:
>
>
>From: Dieter Menne <dieter.menne at menne-biomed.de>
> > Date: Wed, Jul 27, 2011 at 8:44 AM
> > Subject: Re: [R] lattice overlay
> > To: r-help at r-project.org
> >
> >
> >
> >
> > Ram H. Sharma wrote:
> > >
> > > I want to overlay lattice scatter plot: I do not know why the following
> > > code
> > > is not plotting subscripts ! Sorry if this question is too simple:
> > >
> > > Working example shortened:
> > >
> > > .....panel.xyplot(x, y, pch=16, col = "green4", ylim = c(0, 10))
> > >
> > >
> >
> > Because they are out of range. Put ylim outside the panel, and it works.
> >
> > Dieter
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/lattice-overlay-tp3698303p3698357.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > 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.
> >
> >
>
>
>--
>
>Ram H
>
>         [[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.

I have come late to this and must now go but try below:
You may not have seen everything plotted because of panel limits in x 
and y and setting type to "r" will save a line + putting it in the 
main argument will need ...
If you want special axis limits check out the latticeExtra package or 
search for axis limits in previous posts eg ? 
http://finzi.psych.upenn.edu/R/Rhelp02/archive/43626.html

xyplot(Sepal.Length ~ Sepal.Width | Species , data= iris,
        as.table=T,
        subscripts=T,
        ylim = c(0,10),
        xlim = c(0,10),
        type = c("p","r"),
        panel= function(x, y, subscripts, ...) {

                 panel.xyplot(x, y, pch=16, col = "green4",...)

                 panel.xyplot(x=iris$Petal.Length[subscripts], 
y=iris$Petal.Width[subscripts], col = "red",...)


       }
)

Regards

Duncan Mackay

Regards

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



More information about the R-help mailing list