1

有人可以帮我升级我的情节吗?a) 在图中,每行应该只打印一个 y 刻度。b) 要打印更舒适的图例,这意味着 1) 更改符号和描述的顺序,2) 在相同的 x 位置打印行,如 superpose.symbols,3) 并打印直方图的符号。

d1 <- data.frame(x=c(NA, 13:20, NA), y = 25, z = c(rep('march', 5),
rep("april", 5)), color = c(c(rep(c("red", "green"), 2), "red"),
c(rep(c("blue", "yellow"), 2), "blue")), stringsAsFactors = FALSE)
d2 <- data.frame(x=c(NA, 20:27, NA), y = 23, z = c(rep('may', 5),
rep("june", 5)), color = c(c(rep(c("blue", "red"), 2), "red"),
c(rep(c("blue", "yellow"), 2), "blue")), stringsAsFactors = FALSE)
d1<-rbind(d1,d2)
sup.sym <- trellis.par.get("superpose.symbol")
sup.sym$alpha<-c(1, 0, 0, 0, 0, 0, 0)
sup.sym$col<-c(1,2,3,4,5,6,7)

sup.lin <- trellis.par.get("superpose.line")
sup.lin$col<-c(1,2,7,5,5,6,7)
sup.lin$alpha<-c(0, 1, 1, 1, 0, 0, 0)
settings<-list(superpose.symbol = sup.sym,superpose.line = sup.lin)


xyplot(y ~ x | factor(z), data = d1
       ,ylim = list( c(22, 26),c(22, 26), c(0, 1),c(0, 1) )
       ,layout=c(2,2)
       ,scales = list(y = list( relation = "free"  ))
       ,par.settings = settings
       ,auto.key = list(text = c("A","B","C", "D")
                ,space = "right"
                ,lines = TRUE
               )
       ,panel = function(x, y, subscripts) {
                if(panel.number()>2){
                  panel.histogram(x,breaks=3)
                }else{
                  panel.xyplot(x = x, y = y, 
                               subscripts=subscripts,
                               col = d1[subscripts, "color"])

               }
})
4

0 回答 0