1) 屏幕
绘制两次温度曲线,一次作为直线,使用
na.approx
填充空NAs以防止线路断开,并再次使用点以使点可见。使用
screens=
指定要在同一面板上叠加线和点的步骤。
plot(cbind(data.zoo, na.approx(data.zoo$Temperature)),
screens = c("Rain", "Temperature", "Temperature"),
type = c("h", "p", "l"),
lwd = c(5, 1, 1),
col = c("red", "blue", "blue"),
main = "Temperature and Rain")
2) 面板
也可以使用自定义面板功能执行此操作:
my.panel <- function(x, y, ..., pf = parent.frame()) {
if (pf$panel.number == 1) {
lines(x, y, type = "h", col ="red", lwd = 5)
} else {
lines(x, na.approx(y), col = "blue")
points(x, y, col = "blue")
}
}
plot(data.zoo, panel = my.panel, main = "Temperature and Rain")
这两种方法中的任何一种都会产生以下输出: