# Load example data in long format
data(volcano)
volcano3d <- reshape2::melt(volcano)
names(volcano3d) <- c("x", "y", "z")
# Contour plot with default options
v <- contourPlot2(volcano3d)
v
# Set levels, and properly format the legend title:
contourPlot2(volcano3d,
levels = c(-Inf, seq(100, 200, 20), Inf),
legend = expression(PM[10]~"["~mu*g~m^-3~"]"))
# Sometimes, instead of a contour plot it is better to plot the original
# raster data, without any interpolation:
contourPlot2(volcano3d,
levels = c(-Inf, seq(100, 200, 20), Inf),
tile = TRUE)
# Since contourPlot2 returns a `ggplot2` object, you can add instructions as:
library(ggplot2)
v + ggtitle("Example volcano data") +
labs(x = NULL, y = NULL)
Run the code above in your browser using DataLab