2012-09-05 50 views
2

如何在所有底部面板下顯示軸?在此示例中,如果存在缺少方格的網格,則不會顯示該軸。需要所有面板下的軸

library(lattice) 
arr<- array(replicate(10, rnorm(10)), dim =c(10,10,10)) 
dotplot(arr, type = "b", horizontal = F, col = "red", 
    main =list(" Centrality", cex=1.5), xlab.top="",as.table=T, 
    ylab =list("Centralities", cex=1.3), 
    xlab = list("Proportion Cutpoints"), 
    scale=list(y=list(cex=1.2, alternating =1), cex =1), 
    auto.key=list( points = F, border= "grey", 
         space = "top", lines = T, columns=4,height=10, 
         title = "Technologies"), 
    par.settings = list(superpose.line = list(col = "red", lwd=2, lty=1:6), 
         layout.heights= list(xlab.key.padding = 1), 
         layout.widths = list(key.ylab.padding = 1)), 
    par.strip.text = list(cex=1.5)) 

Missing labels

回答

1

您必須修改負責繪製軸的功能。
簡單的方法是強制軸指定面板:

axis_filled <- function(side, ...) { 
    if (side=="bottom" && panel.number() %in% c(7,8)) { 
     axis.default(side = side, labels="yes", ticks="yes", ...) 
    } else { 
     axis.default(side = side, ...) 
    } 
} 

dotplot(arr, type = "b", horizontal = F, col = "red", 
    main =list(" Centrality", cex=1.5), xlab.top="",as.table=T, ylab =list("Centralities", cex=1.3), xlab = list("Proportion Cutpoints"), 
    scale=list(y=list(cex=1.2, alternating =1), cex =1), 
    auto.key=list(points = FALSE, border= "grey", space = "top", lines = TRUE, columns=4,height=10, title = "Technologies"), 
    par.settings = list(superpose.line = list(col = "red", lwd=2, lty=1:6),       layout.heights= list(xlab.key.padding = 1), layout.widths = list(key.ylab.padding = 1)), 
    par.strip.text = list(cex=1.5), 
    axis=axis_filled 
) 

Labels filled

更通用的解決方案couls接力檢查面板填滿。例如:

axis_filled <- function(side, ...) { 
    force_axis <- if (side=="bottom") { 
     panel.layout <- trellis.currentLayout("panel") 
     # next to last row and nothing below: 
     current.row() == nrow(panel.layout)-1 && panel.layout[current.row()+1,current.column()]==0 
    } else FALSE 
    if (force_axis) { 
     axis.default(side = side, labels="yes", ticks="yes", ...) 
    } else { 
     axis.default(side = side, ...) 
    } 
}