-
Book Overview & Buying
-
Table Of Contents
ggplot2 Essentials
By :
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...
Change the font size
Change margin width
Change background colour