Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ggplot2 Essentials

You're reading from   ggplot2 Essentials Explore the full range of ggplot2 plotting capabilities to create meaningful and spectacular graphs

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781785283529
Length 234 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Donato Teutonico Donato Teutonico
Author Profile Icon Donato Teutonico
Donato Teutonico
Arrow right icon
View More author details
Toc

Plotting heatmaps with ggplot2


Heatmaps are representations of matrix data where the individual values contained are represented as colors. Heatmaps can be realized in ggplot2 using the traditional functions available, but we have also included plots in this chapter that represent very specific type of graphs.

In order to realize a heatmap with ggplot2, you will simply need to use the geom_tile() function. These plots can be realized usually by representing two variables on both axes and the combinations between these variables are color-mapped using a third variable. Let's first create a simple dataset that we can use.

x1 <- seq(-10, 10, length.out = 10)
y1 <- seq(-10, 10, length.out = 10)
d1 <- expand.grid(x = x1, y = y1)

d1$z <- d1$x^2 - d1$y^2

We will generate two vectors and then generate all possible combinations between these vectors using the expand.grid().function. We will then just create a third variable, which is a function of the previous ones. What we end up with...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image