1

我有一个格子图,显示三个系列,在条带中标记为 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

谢谢您的帮助。

4

1 回答 1

1

您可以重命名条带标签:

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
于 2013-09-26T12:15:11.970 回答