O'Reilly logo

R: Data Analysis and Visualization by Ágnes Vidovics-Dancs, Kata Váradi, Tamás Vadász, Ágnes Tuza, Balázs Árpád Szucs, Julia Molnár, Péter Medvegyev, Balázs Márkus, István Margitai, Péter Juhász, Dániel Havran, Gergely Gabler, Barbara Dömötör, Gergely Daróczi, Ádám Banai, Milán Badics, Ferenc Illés, Edina Berlinger, Bater Makhabel, Hrishi V. Mittal, Jaynal Abedin, Brett Lantz, Tony Fischetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating heat maps of a single Z variable with a scale

In this recipe, we will make a heat map that shows the variation in values of one variable (z) along the x and y axes as a grid of colors and display a scale alongside.

Getting ready

We will only use the base graphics functions for this recipe. So, just open up the R prompt and type in the following code. We will use the sales.csv example dataset for this recipe. So, let's first load it:

sales<-read.csv("sales.csv")

We will use the RColorBrewer package for some good color palettes. So, let's make sure that it's installed and loaded:

install.packages("RColorBrewer")
library(RColorBrewer)

How to do it...

The sales dataset has monthly sales data for four cities. Let's make a heat map with the months ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required