在所有面板下需要轴

时间:2012-09-05 18:59:38

标签: r lattice

如何在所有底部面板下显示轴?在此示例中,如果存在缺少方块的网格,则不显示轴。

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 个答案:

答案 0 :(得分: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

检查面板上的更多通用解决方案继电器填满。例如:

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, ...)
    }
}