我有时有问题与使用连续当图例不显示颜色的整个范围fill或color尺度,例如scale_fill_continuous,scale_fill_gradient,scale_fill_gradientn(和相应的color尺度).
特别是colorbar图例的上限范围被截断,即它不会一直延伸到调色板的上限.此外,图例的标题垂直调整为(截断的)colorbar,而不是上限.
一个小例子:
# set up data, base plot, limits, labels and breaks
# adjust theme for legend just to make the issue more visible
df <- data.frame(x = 1:4, y = 1, col = c(0.1, 0.3, 0.5, 0.7))
library(ggplot2)
p <- ggplot(data = df, aes(x, y, fill = col)) +
geom_point(size = 15, shape = 21) +
theme_minimal() +
theme(legend.background = element_rect(fill = …Run Code Online (Sandbox Code Playgroud)