library(ggplot2)
# Creates a noisy version of the volcano dataset and applies the smooth
volcano <- reshape2::melt(datasets::volcano, value.name = "original")
volcano$noisy <- with(volcano, original + 1.5*rnorm(length(original)))
volcano$smooth_svd <- with(volcano, Smooth2D(Var2, Var1, noisy, method = smooth_svd(0.005)))
volcano$smooth_dct <- with(volcano, Smooth2D(Var2, Var1, noisy, method = smooth_dct(kx = 0.4)))
volcano <- reshape2::melt(volcano, id.vars = c("Var1", "Var2"))
ggplot(volcano, aes(Var1, Var2)) +
geom_contour(aes(z = value, color = after_stat(level))) +
scale_color_viridis_c() +
coord_equal() +
facet_wrap(~variable, ncol = 2)
Run the code above in your browser using DataLab