0

我的代码生成了 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)
     })

我假设他们会按照他们进入的顺序出现,从列表的顶部开始,并从左上角绘制。

4

1 回答 1

2

要获得您期望的绘图顺序,也许可以尝试添加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).
于 2012-07-10T12:00:13.663 回答