Closed acpguedes closed 3 years ago
Thanks! I'll look into it!
I can't reproduce on the CRAN version of ggnewscale, but can on the dev version. For now, try installing ggnewcale with install.packages("ggnewscale")
.
Investigating further, The issue with the disappearing guides is that ggplot2 is merging them because they have the same name and values (see: https://github.com/tidyverse/ggplot2/issues/4280).
There's nothing I can do from ggnewcale side of things. What you can do is to change the name
argument of each scale (which you should do anyway for clarity!)
library(tidyverse)
library(ggsci)
library(ggnewscale)
data(mtcars)
mtcars %>%
rownames_to_column("rnames") %>%
as_tibble() %>%
mutate_all(as_factor) %>%
select(rnames, vs, am, gear, carb) %>%
gather(key = "key", value = "value", -rnames) -> temp
#> Warning: attributes are not identical across measure variables;
#> they will be dropped
ggplot() +
geom_tile(
data = temp %>% filter(key=="vs") %>% droplevels,
aes(key, rnames, fill=value)
) +
scale_fill_simpsons(name = "simpsns") +
new_scale_fill() +
geom_tile(
data = temp %>% filter(key=="am") %>% droplevels,
aes(key, rnames, fill=value)
) +
scale_fill_rickandmorty(name ="rick") +
new_scale_fill() +
geom_tile(
data = temp %>% filter(key=="gear") %>% droplevels,
aes(key, rnames, fill=value)
) +
scale_fill_futurama(name ="futurama") +
new_scale_fill() +
geom_tile(
data = temp %>% filter(key=="carb") %>% droplevels,
aes(key, rnames, fill=value)
) +
scale_fill_tron(name ="tron") +
theme(legend.position="bottom")
Created on 2020-12-01 by the reprex package (v0.3.0)
I'm closing this for now, since it's something on ggplot2 side of things.
Thank you, this solution you give me is enough
Hi,
Thanks for this package which makes it easy to deal with scales. I think it might be a BUG.
I was trying to do a
geom_tile
with categorical values on the x and y-axis where each value along the x-axis has its color scale.A heatmap where each column has a color scale and legend
So, I manipulated
mtcars
just to test code, and BANG, after the last tile I missed the legend. Full example is hereHere is the code I did.
Created on 2020-11-30 by the reprex package (v0.3.0)
Thanks in advance.