In this recipe, we will learn how to make a contour plot with the areas between the contours filled with a solid color.
We will only use the base graphics functions for this recipe. So, just open up the R prompt and type the following code. We will use the inbuilt volcano
dataset, so we need not load anything.
Let's make a filled contour plot showing the terrain data of the Maunga Whau volcano in R's in-built volcano dataset:
filled.contour(x = 10*1:nrow(volcano),y = 10*1:ncol(volcano), z = volcano, color.palette = terrain.colors, plot.title = title(main = "The Topography of Maunga Whau", xlab = "Meters North",ylab = "Meters West"), plot.axes = {axis(1, seq(100, 800, by = 100)) axis(2, seq(100, 600, by = 100))}, key.title = title(main="Height\n(meters)"), key.axes = axis(4, seq(90, 190, by = 10)))