-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
guide_colbar title property adjustment #37
Comments
Hi Hu, thank you for the report! At the risk of sounding slightly rude: no, absolutely not. The reason is that ggplot2 has removed these arguments and they only still work because of a backward compatibility mechanism. The legendry package is not beholden to ggplot2's backward compatibility, so it will not use the old deprecated arguments. The "proper" way of setting such customisations is via the library(tidyverse)
library(legendry)
library(terra)
m <- matrix(1:25, nrow=5, ncol=5)
rm <- rast(m)
# from a "xyz" data.frame
data <- as.data.frame(rm, xy=TRUE)
bwr_colors <- c("blue", "white", "red")
ggplot(data = data,aes(x = x,y = y,fill = lyr.1)) +
geom_tile() +
scale_fill_gradientn(
colors = bwr_colors,
na.value = NA,
limits = c(5, 20), oob = scales::oob_squish,
guide = guide_colbar(
theme = theme_guide(
title.position = "top",
title = element_text(hjust = 0.5)
)
)) +
theme_bw()+
theme(
legend.position = "bottom",
legend.key.width = unit(2, "cm"),
legend.key.height = unit(0.4, "cm")
) Created on 2024-12-16 with reprex v2.1.1 |
Perfect! Thank you for your detailed reply. I read what you mentioned carefully and this does work well to unify the various attribute contents of the guide using the theme framework! |
Sorry to bother you again. See details: |
You're right this seems like a bug. I'm tracking it in #41. |
Dear Teun van den Brand,
Can
guide_colbar
addtitle.position
andtitle.hjust
parameters to adjust the title position of the colorbar like guide_colorbar in ggplot?The following code adjusts the position of the colorbar, the position of the colorbar header (top and hjust), but does not set the out-of-range triangle shape:
It's more elegant to use
guide_colbar
when setting the triangle shape, but it doesn't seem to be possible to set the title position of the colorbar:If settings similar to the above are made, an error is prompted:
Best regards
Hu
The text was updated successfully, but these errors were encountered: