I’m trying to align two color scales of ggplots with geom_contour_filled
. Below is a minimum example.
library(ggplot2)
df_1 <- df_2 <- data.frame(
n = rep(seq(0.1, 1, 0.1), each = 10),
r = rep(seq(0.1, 1, 0.1), 10)
)
df_1$value <- df_1$n + df_1$r
df_2$value <- df_2$n + df_2$r + 0.2
p1 <- ggplot(df_1, aes(x = n, y = r, z = value)) +
geom_contour_filled(breaks = seq(0, 2, length.out = 21)) +
theme(legend.position = "bottom")
p2 <- ggplot(df_2, aes(x = n, y = r, z = value)) +
geom_contour_filled(breaks = seq(0, 2, length.out = 21)) +
theme(legend.position = "bottom")
p1+p2
The expectation both color scales should be the same. Aligning breaks
doesn’t help, please do not combine two data frames, I need the freedom to use two ggplots separately.
Thanks.