Heatmap with smoothing - LatticeExtra



The latticeExtra package allows to build a heatmap with smoothing. Here is how with reproducible code.

Heatmap section Data to Viz

The levelplot function of lattice allows to deal with 3 numeric variables as shown in the heatmap section of the gallery.

Here, the idea is to plot data points as circles using panel.levelplot.points to get a scatterplot. Then, a layer is added using panel.2dsmoother to show the general distribution of the third numeric variable.

# library
library(latticeExtra) 
 
# create data
set.seed(1) 
data <- data.frame(x = rnorm(100), y = rnorm(100)) 
data$z <- with(data, x * y + rnorm(100, sd = 1)) 
 
# showing data points on the same color scale 
levelplot(z ~ x * y, data, 
          panel = panel.levelplot.points, cex = 1.2
    ) + 
    layer_(panel.2dsmoother(..., n = 200))

Related chart types


Scatter
Heatmap
Correlogram
Bubble
Connected scatter
Density 2d



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥