Book Image

R Data Visualization Cookbook

Book Image

R Data Visualization Cookbook

Overview of this book

Table of Contents (17 chapters)
R Data Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Generating a heat map with customized colors


In the previous recipe, we prepared our data and created a heat map. The heat map was constructed using the default color scheme. What if we would like to plot a heat map using a softer colors? This recipe dives into plotting a heat map by customizing colors. The heat map for Iraq body count is as follows:

Getting ready

For implementing a customized color scheme in our heat map, we require the following two packages available developed for R:

  • pheatmap

  • RColorBrewer

How to do it…

We start the recipe by installing the necessary packages and loading the same in our active R session:

install.packges(c("pheatmap","RColorBrewer"))
library(RColorBrewer)
library(pheatmap)

Next, we can import the data and process the same. The steps in the following code are the same as discussed in previous recipes:

irq = read.csv("iraqbdc.csv", header = TRUE, sep =",")
row.names(irq) = irq$years
irq = data.matrix(irq)
irq = data.matrix(irq[,2:13])

Since we would like the chart...