I sometimes have problems with a legend that does not display the entire range of colors when using a continuous fill or color scale, such as scale_fill_continuous , scale_fill_gradient , scale_fill_gradientn (and the corresponding color scales) ,.
In particular, the upper range of the colorbar legend colorbar truncated, i.e. it does not extend to the upper limit of the color palette. In addition, the name of the legend is vertically adjusted to the (truncated) colorbar , and not to the upper limit.
A small example:
# set up data, base plot, limits, labels and breaks

Similarly for scale_fill_gradientn :
p + scale_fill_gradientn(colours = c("black", "white"), name = "Title", limits = li, labels = la, breaks = br) # and scale_fill_gradient # p + scale_fill_gradient(low = "black", high = "white", # name = "Title", limits = li, labels = la, breaks = br)

As you can see, although the highest color value is 0.7, and the dot is correctly colored on the graph with the end of the color palette, the colorbar truncated in the upper range - despite the fact that the limits are clearly set - and the name is in the wrong position.
This problem arose on several machines and occurs regardless of the selected palette or theme() , but I only saw it in the upper range. If you change the upper limit of the color scale, sometimes it works, and sometimes not.
The following code generates the corresponding problem for the color scales:
p <- ggplot(data = df, aes(x, y, color = col)) + geom_point(size = 15) + theme_minimal() + theme(legend.background = element_rect(fill = "grey60"), legend.text = element_text(size = 18), legend.key.size = unit(1.5, "cm")) p + scale_color_continuous(limits = li, labels = la, breaks = br) p + scale_color_gradientn(colours = c("black", "white"), limits = li, labels = la, breaks = br) p + scale_color_gradient(low = "black", high = "white", limits = li, labels = la, breaks = br)
Can anyone give an idea?