Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating filled contour plots


In this recipe, we will learn how to make a contour plot with the areas between the contours filled with a solid color.

Getting ready

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.

How to do it...

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)))

How it works...

If you type in ?filled.contour, you will see that the preceding example is taken from that help file (see the...