[R] lattice, xyplot, using "panel.segments" by just addressing one panel
Peter Ehlers
ehlers at ucalgary.ca
Wed Jun 2 17:28:19 CEST 2010
Doris,
You might get lucky and find some kind soul who's willing to
dig through your *un*reproducible code, but your chances for
help would probably increase dramatically if you were to
provide *reproducible* and *minimal* code to illustrate your
problem. I imagine that you might benefit from reading the
posting guide.
It may be that trellis.focus() solves your problem.
-Peter Ehlers
On 2010-06-02 8:46, Doris wrote:
>
> Hi R experts,
>
> I'm using the xyplot function in lattice to draw a multipanel plot consiting
> of 5x6 scatterplots.
> Now I need to link single points in each of those scatterplots (=panel),but
> the points, that need linking are different for each panel.
> I tried to use the panel.segments function for that, but I can't address
> each panel separately. Links right for panel 1, show up in all other panels,
> too. Tried functions like [panel.number()], but didn't work.
>
> Would be so great, if somebody could help me with that!
>
> That's the code, I used:
>
> library(lattice)
> library(latticeExtra)
> #[...]
> attach(mydata)
> attach(links) #containing the coordinates for the segments fx, fy, tx, ty
>
> fx<- fx
> fy<- fy
> tx<- tx
> ty<- ty
>
> xyplot(LogN~LogM|factor(surber),
> par.settings = list(strip.background = list(col = "transparent")),
> xlab = "Log M", ylab = "Log N",
> layout = c(6,5), aspect = 1, as.table = TRUE, strip=FALSE,
> panel=function(x,y){
> panel.xyplot(x,y,pch=20,col="black", bg="transparent")
> panel.fill(col = "transparent")
> panel.segments(fx,fy,tx,ty[panel.number()])
>
> })
>
>
> Also tried to split the data and loop it (but this code might be a bit
> messy. Apologies!) sn is the variable used to split according to panel. I
> just tried to do the links for 2 panel here:
>
> fx<- split(links$fx,links$sn)
> fy<- split(links$fy,links$sn)
> tx<- split(links$tx,links$sn)
> ty<- split(links$ty,links$sn)
> sn<- sn
> dothese<- c(1,2)
> ct<- 0
> for (i in dothese){
> ct<- ct + 1
> x1<- fx[[i]]
> y1<- fy[[i]]
> x2<- tx[[i]]
> y2<- ty[[i]]
> }
>
>
> xyplot(LogN~LogM|factor(surber),
> par.settings = list(strip.background = list(col = "transparent")),
> xlab = "Log M", ylab = "Log N",
> layout = c(6,5), aspect = 1, as.table = TRUE, strip=FALSE,
> panel=function(x,y){
> panel.xyplot(x,y,pch=20,col="black", bg="transparent")
> panel.fill(col = "transparent")
> panel.segments (x1,y1,x2,y2 [panel.number(1,2)])
>
> })
>
>
>
> Thanks, Doris
More information about the R-help
mailing list