仅作记录,由于格子图的全面自定义选项,我似乎终于想出了一个合适的解决方案。在执行和随后使用自定义 y 轴的组合图之前禁用scales
上图(通过scales = list(draw = FALSE)
;请注意,文件 'rsq.rds' 已在线更改)解决了该问题。c.trellis
update
## combine plots and increase left padding
plt <- latticeExtra:::c.trellis(rsq_plt, err_plt, layout = c(1, 2))
plt <- update(plt,
scales = list(draw = FALSE),
par.settings = list(
layout.widths = list(left.padding = 6, right.padding = 0),
layout.heights = list(top.padding = 0, bottom.padding = 0)
))
## custom panel.axis
panel.fun <- function(...) {
# allow to draw labels outside panel
trellis.par.set("clip", list(panel = "off", strip = "off"))
# add upper y-axis
if (panel.number() == 1) {
panel.axis("left", at = 1, tck = .5, outside = TRUE,
labels = expression("r"^2))
panel.abline(v = 1, lty = 3, lwd = 1, col = "red")
panel.dotplot(lwd = .5, ...)
}
# add lower y-axis
if (panel.number() == 2) {
panel.axis("left", at = 2:4, outside = TRUE, tck = .5,
labels = c("MAE", "ME", "RMSE"))
panel.abline(v = 0, lty = 3, lwd = 1, col = "red")
panel.dotplot(..., lwd = 0.5)
}
}
## apply custom axes
update(plt, panel = panel.fun)