我有一个格子图表显示三个系列,在条带中标记为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
感谢您的帮助。
答案 0 :(得分: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