Unfortunately the dataset in use is not available, so there is no way to faithfully reproduce the image and expand the details.
To create the contour surface, it is interesting to use the ggplot2
package with the geom_raster
function. But this will return a continuous surface.
library(ggplot2)
library(dplyr)
x <- seq(1, 6, 1)
y <- seq(0, 3, 1)
grid <- expand.grid(x = x,
y = y)
m <- matrix(c(7,73,195,195,416,625,120,52,178,178,349,454,6,
83,164,164,244,0,3,52,150,150,329,330),
nrow = 4, ncol = 6, byrow = T)
m2 <- m %>%
t %>% as.data.frame()
grid <- grid %>%
dplyr::mutate(response = c(m2$V1, m2$V2, m2$V3, m2$V4))
Palet <- c("royalblue2", "orangered3", "lavenderblush3", "gold3")
ggplot2::ggplot(grid, aes(x, y, z = response)) +
geom_raster(aes(fill = response)) +
scale_fill_gradientn(colours = Palet, limits = c(0, 800)) +
theme_void() +
theme(legend.position = "bottom")

In addition, it is possible to perform data manipulation and work with the discrete fill
. Where for each interval, a color will be assigned.
grid2 <- grid %>%
dplyr::mutate(cor = ifelse(response >= 0 & response < 200, 1,
ifelse(response >= 200 & response < 400, 2,
ifelse(response >= 400 & response < 600, 3,
ifelse(response >= 600, 4, "error")))))
ggplot2::ggplot(grid2, aes(x, y, z = response)) +
geom_raster(aes(fill = cor)) +
scale_fill_manual(values = Palet, labels = c("0-200", "200-400",
"400-600", "600-800"),
name = "") +
theme_void() +
theme(legend.position = "bottom")

However, if it is considered that in matrix m
each cell is intensity, it is possible to generate a 3D plot.
library(plot3D)
persp3D(z = m, theta = 60)

3D surface plot from 2D matrix
Plot 3D data in R
Impressive package for 3D and 4D graph - R software and data visualization