-
Notifications
You must be signed in to change notification settings - Fork 9
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
variable-dependent fills not rendering in geoms stacked on geom_spatial_rgb #72
Comments
So this is a ggplot thing, not a terrainr thing, and it comes down to a relatively simple explanation: there's no easy way to have more than one This is why color works: it's a different aesthetic, so there's no conflict. As for workarounds... I unfortunately don't have a ton for you. One option is to use the old, seemingly abandoned relayer package (unfortunately ggnewscale doesn't seem to work), as so:
It's not a great workaround (note the no legend, for instance) but it's something. Apologies I don't have a better solution for you here; my understanding is that this (the assumption that only one variable can be mapped to an individual aesthetic) is baked deep into how ggplot works. |
Thanks for this very helpful response (and workaround), Mike. It makes perfect sense that there can't be two fills for fundamental ggplot reasons. What is interesting is that fills do work so long as they are outside of the aes, i.e. static calls rather than variable dependent. Yet another workaround is to define the fills in advance (i.e. by mapping them onto values), and then call the vector of colors. Here's an example building off the previous reprex in case anyone is interested: label_scale <- cut(scale(random_points_df$label), breaks = seq(from = -2, to = 2, len = 100), include.lowest = T)
my.cols <- RColorBrewer::brewer.pal(3, "RdBu")
random_points_df$label_cols = colorRampPalette(my.cols)(99)[label_scale]
ggplot() +
geom_spatial_rgb(data = output_tiles[["ortho"]], aes(x = x, y = y, r = red, g = green, b = blue)) +
geom_point(data = random_points_df, aes(x = x, y = y, size = label), fill = random_points_df$label_cols, shape = 21) +
coord_sf(crs = 4326) +
scale_size_continuous(breaks = seq(from = 0, to = 500, by = 100), limits = c(100, 500)) |
Hi all,
I am wondering if I have encountered a bug or do not yet fully grasp the syntax of the (excellent)
geom_spatial_rgb
. In short, the issue I am encountering is that when a fill is set to a variable in a geom that is stacked on top of ageom_spatial_rgb
object, that fill does not render, and in fact, interrupts the code computation or else generates some seriously funky colors.Here is a reprex:
Session Info
The text was updated successfully, but these errors were encountered: