Using a 3D histogram

The three-dimensional histogram function, hist3D(), has the following attributes:

  • z: Values contained within a matrix.
  • x, y: Vectors, where length of x should be equal to nrow(z) and length of y should be equal to ncol(z).
  • colvar: Variable used for the coloring and has the same dimension as z.
  • col: Color palette used for the colvar variable. By default, a red-yellow-blue color scheme.
  • add: Logical variable. If TRUE, adds surfaces to the current plot. If FALSE, starts a new plot.

Let's plot the Death rate of Virgina using a 3D histogram:

data(VADeaths)hist3D(z = VADeaths, scale = FALSE, expand = 0.01, bty = "g", phi = 20, col = "#0085C2", border = "black", shade = 0.2, ltheta = 80, space = 0.3, ticktype = "detailed", ...

Get R Data Analysis Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.