# library
library(latticeExtra)
# create data
set.seed(1)
data <- data.frame(x = rnorm(100), y = rnorm(100))
data$z <- with(data, x * y + rnorm(100, sd = 1))
# showing data points on the same color scale
levelplot(z ~ x * y, data,
panel = panel.levelplot.points, cex = 1.2
) +
layer_(panel.2dsmoother(..., n = 200))
参考文献:https://r-graph-gallery.com/201-levelplot-with-latticeextra.html