Heat maps are colorful images that are very useful to summarize a large amount of data by highlighting hotspots or key trends in the data.
There are a few different ways to make heat maps in R. The simplest is to use the heatmap()
function in the base library:
heatmap(as.matrix(mtcars), Rowv=NA, Colv=NA, col = heat.colors(256), scale="column", margins=c(2,8), main = "Car characteristics by Model")
The example code has a lot of arguments, so it might look difficult at first sight. However, if we consider each argument in turn, we can understand how it works. The first argument to the heatmap()
function is the dataset. We are using the built-in dataset mtcars
, which holds data such as fuel efficiency (mpg
), number of cylinders (cyl
), weight (wt
), and so on for different models of cars. The data needs to be in a matrix format, so we use the as.matrix()
function. Rowv
and Colv
specify whether and how dendrograms should be displayed to the left...