В дополнение к моему комментарию выше, давайте поместим оба графика рядом
gg1 <- ggplot(data, aes(X, Y, fill = Z)) +
geom_tile() +
scale_fill_distiller(palette = "Reds", direction = +1) +
labs(x = NULL, y = NULL) +
theme_minimal()
gg2 <- ggplot(data, aes(X, Y, fill = Z)) +
geom_tile() +
scale_fill_distiller(palette = "Reds", direction = -1) +
labs(x = NULL, y = NULL) +
theme_minimal()
library(gridExtra)
g <- grid.arrange(gg1, gg2)
Причину поведения, которое вы видите вышеscale_fill_distiller
предполагает direction = -1
по умолчанию:
scale_fill_distiller
#function (..., type = "seq", palette = 1, direction = -1, values = NULL,
# space = "Lab", na.value = "grey50", guide = "colourbar",
# aesthetics = "fill")
#{
# type <- match.arg(type, c("seq", "div", "qual"))
# if (type == "qual") {
# warning("Using a discrete colour palette in a continuous scale.\n Consider using type = \"seq\" or type = \"div\" instead",
# call. = FALSE)
# }
# continuous_scale(aesthetics, "distiller", gradient_n_pal(brewer_pal(type,
# palette, direction)(7), values, space), na.value = na.value,
# guide = guide, ...)
#}
#<bytecode: 0x7fed742ed1d8>
#<environment: namespace:ggplot2>