Question Details

No question body available.

Tags

r ggplot2 heatmap patchwork

Answers (1)

April 8, 2026 Score: 4 Rep: 131,461 Quality: Medium Completeness: 80%

Instead of using patchwork an alternative approach would be to use the ggnewscale package to create your desired result as one chart, where ggnewscale allows you to map multiple variables onto the same aesthetic and include a legend for each.

First, I create two named lists: one for the variables to be mapped onto fill, and one for the fill scales. Secondly, I loop over the first list using purrr::imap to add a geomtile and the respective fill scale for each variable.

library(tidyverse)
library(palmerpenguins)

var
fill