[R] Different number of labels in different panels
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Dec 31 17:40:13 CET 2007
Use this panel function:
function(x,y,subscripts,...){
panel.superpose(x, y, subscripts, ...)
grps <- as.character(sort(unique(dataframe[subscripts,2])))
draw.key(simpleKey(grps), TRUE, vp = viewport(0.15, 0.9))
}
The code below is the same as in your post except we have added
library(grid) and replaced the panel function with the above one:
library(lattice)
library(grid)
column1=c(1,1,1,1,1,1,2,2)
column2=c(1,1,1,2,2,2,1,1)
column3=c(1,2,3,1,2,3,4,5)
column4=c(111,112,113,121,122,123,211,212)
dataframe=data.frame(panelnumber=column1,curvenumber=column2,x=column3,y=column4)
xyplot(dataframe[,4]~dataframe[,3]|dataframe[,1],type="l",lty=1,groups=dataframe[,2],layout=c(2,1),aspect=1,
panel=function(x,y,subscripts,...){
panel.superpose(x, y, subscripts, ...)
grps <- as.character(sort(unique(dataframe[subscripts,2])))
draw.key(simpleKey(grps), TRUE, vp = viewport(0.15, 0.9))
}
)
On Dec 31, 2007 10:41 AM, Hofert Marius <m_hofert at web.de> wrote:
> Hi,
>
> I would like to put a number to each of the plotted curves in each
> panel. The problem is that there are different numbers of curves in
> different panels, so as you can see from the code below, I could put
> the correct numbers to the curves in the first panel, but for the
> second panel, both location and number of labels are incorrect (I
> would like to have "(1)" at location x=3.5, y=211 and of course no
> label "(2)" in the second panel). What is the correct way to solve
> this? I have a vector where the i-th entry specifies the number of
> curves in panel i, so I somehow have to bring this vector into play...
>
> Thanks very much in advance.
>
> Marius
>
> library(lattice)
> column1=c(1,1,1,1,1,1,2,2)
> column2=c(1,1,1,2,2,2,1,1)
> column3=c(1,2,3,1,2,3,4,5)
> column4=c(111,112,113,121,122,123,211,212)
> dataframe=data.frame
> (panelnumber=column1,curvenumber=column2,x=column3,y=column4)
> xyplot(dataframe[,4]~dataframe[,3]|dataframe[,
> 1],type="l",lty=1,groups=dataframe[,2],layout=c(2,1),aspect=1,
> panel=function(...){
> panel.xyplot(...)
> panel.text(3.4,113,label="(1)")
> panel.text(3.4,123,label="(2)")
> }
> )
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list