If midpoint is not half-way between the two values in limits, then the gradient scale extends beyond the limit that is closer to midpoint but the guide stops where limits specifies. Especially in conjunction with na.value, this can mislead the reader.
In this plot the color scale goes below what the guide displays, and values below 2 are not indicated as NA.
library(scales)
library(ggplot2)
library(dplyr)
ggplot(mapping = aes(x = Sepal.Length, y = Sepal.Width) ) +
geom_point(data = iris, aes(color = Petal.Length), size = 2) +
geom_point(data = iris %>% filter(Petal.Length < 2), size = 4, shape = 5, color = "red") +
geom_point(data = iris %>% filter(Petal.Length > 6), size = 4, shape = 0, color = "red") +
scale_color_gradient2(low = muted("green"), high = muted("navy"),
mid = "gray80",
midpoint = 3, limits = c(2, 6),
na.value = "orange")
If we change midpoint to 3, then the scale truly runs from 2 to 6 and values below 2 are
flagged.
ggplot(mapping = aes(x = Sepal.Length, y = Sepal.Width) ) +
geom_point(data = iris, aes(color = Petal.Length), size = 2) +
geom_point(data = iris %>% filter(Petal.Length < 2), size = 4, shape = 5, color = "red") +
geom_point(data = iris %>% filter(Petal.Length > 6), size = 4, shape = 0, color = "red") +
scale_color_gradient2(low = muted("green"), high = muted("blue"),
mid = "gray80",
midpoint = 4, limits = c(2, 6),
na.value = "orange")
If
midpointis not half-way between the two values inlimits, then the gradient scale extends beyond the limit that is closer tomidpointbut the guide stops wherelimitsspecifies. Especially in conjunction withna.value, this can mislead the reader.In this plot the color scale goes below what the guide displays, and values below 2 are not indicated as
NA.If we change
midpointto3, then the scale truly runs from 2 to 6 and values below 2 areflagged.