ggnewscale
ggnewscale copied to clipboard
Issue When Trying to Employ `guide_colourbar` ::::: v0.4.8
Hello @eliocamp,
Thanks a lot for the great tool.
I am running into a problem when I try to call guide_colourbar together with new_scale_fill(). I am not sure if the program is really designed to cover this possibility but it would be lovely if it were.
ggplot() +
geom_raster(data = Salinity_df, aes(x = x, y = y, fill = Present.Surface.Salinity.Mean)) +
scale_fill_gradient2(low = "#f0f0f0", mid = "#969696", high = "#252525", midpoint = 21, n.breaks = 5) +
guides(fill = guide_colourbar(title = "Salinity", title.theme = element_text(size = 16, face = "bold"),
label.theme = element_text(size = 14, face = "bold"), label.position = "top",
barwidth = 10.7, barheight = 1, order = 1, frame.linetype = 1, frame.colour = "#000000",
ticks.colour = "#000000", direction = "horizontal")) +
geom_sf(data = Global, fill = "#fff7f3", colour = "#000000") +
new_scale_fill() +
geom_star(data = Coors_Grouped, aes(x = Longitude, y = Latitude, starshape = Group, fill = BioState),
colour = "#000000", size = 6)
Error in `guides_train()`:
! Guide 'colorbar' cannot be used for 'fill_new'.
May I ask if you would see any potential solution here?
Many thanks in advance, George.
I believe this will be fixed by #53 (can be used today by using remotes::install_github("teunbrand/ggnewscale", ref = "guide_fix")
Thanks. #53 is now merged. Please do confirm if this fixes the issue :)
Still happens for me with v.0.4.9.
I don't know why I didn't see it, but I think the issue is that using guides() doesn't work with ggnewscale. You need to specify the guide in the guide argument of the scale.
This should work:
scale_fill_gradient2(low = "#f0f0f0", mid = "#969696", high = "#252525", midpoint = 21, n.breaks = 5,
guide = guide_colourbar(title = "Salinity", title.theme = element_text(size = 16, face = "bold"),
label.theme = element_text(size = 14, face = "bold"), label.position = "top",
barwidth = 10.7, barheight = 1, order = 1, frame.linetype = 1, frame.colour = "#000000",
ticks.colour = "#000000", direction = "horizontal")))
If you're still having trouble, please send a minimal reproducible example so I can troubleshoot the issue.
Just hit this and can confirm the above workaround as moving guides(fill = guide_colorbar()) into scale_fill cleared the issue for me.