R晶格:包括从面板功能到条带标签的信息

时间:2022-10-22 14:55:46

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)

我有一个格子图表显示三个系列,在条带中标记为A,B,C。在图表中,我使用panel.text添加了最大值。但是,如何在条带名称旁边的条带中添加此信息? (例如在顶部条带中:最大值= 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.

感谢您的帮助。

1 个解决方案

#1


1  

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

#1


1  

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