r-如何指定一组晶格xyplots中的绘图顺序



我的代码生成了9个可爱的散点图。然而,它们以奇怪的顺序出现(似乎从右到左,从要绘制的列列表的底部开始)。

有没有办法指定它们的打印顺序?

我的代码如下。

Z <- as.vector(as.matrix(sample_clean_data[, c("agri_dist", "allroads_dist", "DES_dist",
                                "elevation", "river_dist", "pop_dens",
                                "slope", "urban_dist", "LS_dist_to_edge")]))

Y10 <- rep(sample_clean_data$change, 9)
MyNames <- names(sample_clean_data[,c("agri_dist", "allroads_dist", "DES_dist",
                       "elevation", "river_dist", "pop_dens",
                       "slope", "urban_dist", "LS_dist_to_edge")])
ID10 <- rep(MyNames, each = length(sample_clean_data$change))
library(lattice)

ID11 <- factor(ID10, labels = c("Distance to nearest agriculture",  
                            "Distance to nearest road", 
                            "Distance to Dar es Salaam", 
                            "Elevation (m)", 
                            #"Distance to nearest main road", 
                            "Distance to nearest major river", 
                            "Population density (indiv./km2)",
                            "Slope",
                            "Distance to nearest urban centre",
                            "Landsat - Distance to forest edge"
),
           levels = c("agri_dist", "allroads_dist", "DES_dist",
                      "elevation", "river_dist", "pop_dens",
                      "slope", "urban_dist", "LS_dist_to_edge"))    
 xyplot(Y10 ~ Z | ID11, col = 1,
   strip = function(bg='white',...) strip.default(bg='white',...),
   scales = list(alternating = F,
                 x = list(relation = "free"),
                 y = list(relation = "same")),
   xlab = "Covariates",
   par.strip.text = list(cex = 0.8),
   ylab = "Change",
   panel=function(x, y, subscripts,...){
     panel.grid(h =- 1, v = 2)
     panel.points(x, y, col = 1, pch = 16)
     })

我以为它们会按照进入的顺序从列表的顶部出来,并从左上角绘制。

若要获得所需的绘图顺序,可以尝试将as.table=TRUE添加到对xyplot()的调用中。

来自?xyplot:

as.table:
    A logical flag that controls the order in which panels should be displayed: 
    if FALSE (the default), panels are drawn left to right, bottom to top (as in 
    a graph); if TRUE, left to right, top to bottom (as in a table).

最新更新