Skip to Content
The R Book
book

The R Book

by Michael J. Crawley
June 2007
Beginner to intermediate
950 pages
27h 8m
English
Wiley
Content preview from The R Book

Complex 3D plots with wireframe

If you want to create really fancy 3D graphics you will want to master the wireframe function, which allows you to specify the location of the notional light source that illuminates your object (and hence creates the shadows). Here are two examples from demo(trellis) that produce pleasing 3D objects. In the first case, the surface is based on data (in the dataframe called volcano), whereas in the second case (strips on a globe) the graphic is based on an equation (z ~ x * y). It is in library(lattice). This is how wireframe is invoked:

wireframe(volcano, shade = TRUE, aspect = c(61/87,
   0.4), screen = list(z = -120, x = -45), light.source = c(0,
   0, 10), distance = 0.2, shade.colors = function(irr, ref,
   height, w = 0.5) grey(w * irr + (1 - w) * (1 - (1 - ref)^0.4)))

Next, we see a shaded globe with the surface turned into strips by leaving out every other pair of coloured orbits by setting their values to NA.

n < - 50
tx<- matrix(seq(-pi, pi, len = 2 * n), 2 * n, n)
ty<- matrix(seq(-pi, pi, len = n)/2, 2 * n, n, byrow = T)
xx < - cos(tx) * cos(ty)
yy <- sin(tx) * cos(ty)

images

zz <- sin(ty)
zzz <- zz
zzz[, 1:12 * 4]<- NA

Now draw the globe and shade the front and back surfaces appropriately:

wireframe(zzz ~ xx * yy, shade = TRUE, light.source = c(3,3,3))
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

The R Book, 2nd Edition

The R Book, 2nd Edition

Michael J. Crawley
The R Book, 3rd Edition

The R Book, 3rd Edition

Elinor Jones, Simon Harden, Michael J. Crawley
R Data Analysis Cookbook, Second Edition - Second Edition

R Data Analysis Cookbook, Second Edition - Second Edition

Kuntal Ganguly, Davor Lozić, Mzabalazo Z. Ngwenya, Andrew Bauman, Shanthi Viswanathan, Viswa Viswanathan

Publisher Resources

ISBN: 9780470510247Purchase book