adam.888
adam.888

Reputation: 7846

R lattice: including information from a panel function into the strip labels

I have a lattice chart showing three series, labelled A,B,C in the strips. Within the charts I have added the max value using panel.text. But how can I add this information within the strips, next to the strip name? (eg in the top strip: A max value=2.61)

 #Libraries used:
 library(lattice)
 #Data: Create three random walks:
 A <-  c(rnorm(99), cumsum(rnorm(99)))
 B <-  c(rnorm(99), cumsum(rnorm(99)))
 C <-  c(rnorm(99), cumsum(rnorm(99)))
 #combine data into a dataframe:
 df1 <- data.frame(A,B,C)
 df1

 #create a time series for use in xyplot:


 ts1 <- ts(df1, start=-100, end=-1, frequency=1) 

#create a lattice chart:

chart1 <-xyplot(ts1    ,
panel=function(x,y)

{

panel.xyplot(x,y)
panel.lines(x,y)

y=round(y,2)
lab1 <- names(y)
panel.text(-80,min( y)*0.9, paste(lab1,"max:",max(y)), cex = 1.2, font =2,col="blue") 
 })
 chart1

Thank you for your help.

Upvotes: 1

Views: 632

Answers (1)

DaveTurek
DaveTurek

Reputation: 1297

You can rename the strip labels:

chart1 <-xyplot(ts1    ,    
panel=function(x,y)    
{    
panel.xyplot(x,y)    
panel.lines(x,y)    
},    
strip= strip.custom(factor.levels=paste(dimnames(ts1)[[2]],"max value =",round(apply(ts1,2,max),2)))    
)    
 chart1

Upvotes: 1

Related Questions