如何向 lattice xyplot 添加更漂亮的动态键(图例)

How to add a prettier dynamic key (legend) to lattice xyplot

我想为我的 xyplot 添加一个动态(自动更改)键。我想显示模拟的不同参数,例如:

但是,我希望这些值在同一行中,紧挨着它们的标签。像 alpha = 0.1

这是我目前使用的代码:



params <- list()
params <- within(params, {
  
  
  alpha <- 0.1
  beta <- 5
  gamma <- 1
  kappa <- 0.5
  delta <- 0.02
  sigma <- 0.1
})


plot(
  xyplot(N.1+N.2+N.3+N.4+N.5+N.6+N.7 ~ time | sprintf("Simulation %02d",nsim), 
         data=result.rep, type=c('l','g'), as.table=T,
         ylab='Infected', xlab='Time',
         scales=list(y=list(alternating=F)),
         key=list( x = .8, y = .4, 
                  text=list(c( "alpha = ", params$alpha, "beta = ", params$beta, "gamma = ", params$gamma, "kappa = ", params$kappa, "delta = ", params$delta, "sigma = ", params$sigma
                               ))
         )
  )
)

我也尝试过在密钥中使用 2 列,但同样没有成功。 应该是比较容易做的事情,但是我至今没能破解。

感谢您考虑这个问题。

编辑: 这是您也可以完全 运行 的代码。虽然问题不大。

time <- seq(1,10)
N.1 <- c(0,0,0,0,0,0,0,0,0,0)
N.2 <- c(0,0,0,0,0,0,0,0,0,0)
N.3 <- c(0,0,0,0,0,0,0,0,0,1)
N.4 <- c(0,1,5,6,10,1,2,2,6,7)
N.5 <- c(0,0,0,0,0,0,0,0,0,0)
N.6 <- c(0,0,1,0,0,0,0,0,0,0)
N.7 <- c(0,1,1,2,2,4,6,6,6,3)
nsim <- c(1,1,1,1,1,1,1,1,1,2,3,4,5)
result_snip <- data.frame(time,N.1,N.2,N.3,N.4,N.5,N.6, N.7)



plot(
  xyplot(N.1+N.2+N.3+N.4+N.5+N.6+N.7 ~ time | sprintf("Simulation %02d",nsim), 
         data=result_snip, type=c('l','g'), as.table=T,
         ylab='Infected', xlab='Time',
         scales=list(y=list(alternating=F)),
         key=list( x = .8, y = .4, 
                   text=list(c( "alpha = ", params$alpha, "beta = ", params$beta, "gamma = ", params$gamma, "kappa = ", params$kappa, "delta = ", params$delta, "sigma = ", params$sigma
                   ))
         )
  )
)

使用 G. Grothendieck 的 paste("alpha =", params$alpha)