Skip to content
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

legend.key fill #29

Open
ASKurz opened this issue Aug 14, 2023 · 9 comments
Open

legend.key fill #29

ASKurz opened this issue Aug 14, 2023 · 9 comments

Comments

@ASKurz
Copy link

ASKurz commented Aug 14, 2023

I think you're gonna want to adjust the fill setting for the legend.key for theme_barbie(). Here's an example of what currently happens:

library(tidyverse)
library(ThemePark)

mtcars %>% 
  ggplot(aes(mpg, wt)) +
  geom_point(aes(shape = factor(cyl))) +
  theme_barbie()
Screenshot 2023-08-13 at 7 01 00 PM

See the default gray background in the legend key? Here are two possible fixes:

mtcars %>% 
  ggplot(aes(mpg, wt)) +
  geom_point(aes(shape = factor(cyl))) +
  theme_barbie(barbie_font = FALSE)  +
  theme(legend.key = element_rect(fill = "white"))

mtcars %>% 
  ggplot(aes(mpg, wt)) +
  geom_point(aes(shape = factor(cyl))) +
  theme_barbie(barbie_font = FALSE)  +
  theme(legend.key = element_rect(fill = barbie_theme_colors["panel"]))
Screenshot 2023-08-13 at 7 02 17 PM Screenshot 2023-08-13 at 7 02 30 PM
@ASKurz
Copy link
Author

ASKurz commented Aug 14, 2023

Here's a more radical option:

mtcars %>% 
  ggplot(aes(mpg, wt)) +
  geom_point(aes(shape = factor(cyl))) +
  theme_barbie()  +
  theme(legend.background = element_rect(fill = "white"),
        legend.key = element_rect(fill = barbie_theme_colors["panel"]))
Screenshot 2023-08-13 at 7 21 27 PM

@MatthewBJane
Copy link
Owner

I actually very much like the "radical" one. I will add this. This one is a bit tedious so I will probably do this tomorrow. I will follow up on this issue once it is done. Thanks for finding these flaws, Solomon!

@ASKurz
Copy link
Author

ASKurz commented Aug 14, 2023

Glad to be of service.

@ASKurz
Copy link
Author

ASKurz commented Aug 14, 2023

Update: To get it right, I think it might have to be this:

mtcars %>% 
  ggplot(aes(mpg, wt)) +
  geom_point(aes(shape = factor(cyl))) +
  theme_barbie()  +
  theme(legend.background = element_rect(fill = "white"),
        # note we're adjusting both fill and color settings
        legend.key = element_rect(fill = barbie_theme_colors["panel"],
                                  color =  barbie_theme_colors["panel"]))

@MatthewBJane
Copy link
Owner

totally forgot to come back to this... @christopherkenny or @lukepilling, is this worth implementing?

@lukepilling
Copy link
Collaborator

Seems like yes for Barbie. Would we need to check the other themes to make sure it didn't look "bad"? Or just implement the solution throughout?

@MatthewBJane
Copy link
Owner

Idk that seems like a huge pain. Probably implementing it in Barbie would be fine for now. Unless you or Chris want to try to implement it across the board. I don't think it is necessary for now though

@christopherkenny
Copy link
Collaborator

FYI, we could clean this up if we have specific choices, but ggplot2 version 3.5.0 has this as a breaking change (which fixes the ugly greys)/

We can see how that looks below:
themes_test.pdf

Code to generate ``` devtools::load_all() library(ggplot2) library(patchwork)

list_fn <- function(prefix) {
fns <- utils::lsf.str("package:ThemePark")
fns[startsWith(fns, prefix)]
}

p <- lapply(list_fn('theme_'), function(fn) {
theme <- getFromNamespace(fn, 'ThemePark')
mtcars |>
ggplot(aes(mpg, wt)) +
geom_point(aes(shape = factor(cyl))) +
theme() +
labs(title = fn)
}) |>
wrap_plots()

ggsave(plot = p, filename = 'themes_test.pdf', width = 48, height = 36)

</details>

@christopherkenny
Copy link
Collaborator

And here's a png version, since it doesn't show as pdf.
themes_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants