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

Feature request: pal_size, pal_alpha, & pal_linewidth #425

Closed
davidhodge931 opened this issue Apr 15, 2024 · 5 comments
Closed

Feature request: pal_size, pal_alpha, & pal_linewidth #425

davidhodge931 opened this issue Apr 15, 2024 · 5 comments

Comments

@davidhodge931
Copy link

Hi,

In the same way that pal_hue, pal_shape and pal_linewidth are useful helpers, could we also have pal_size, pal_alpha and pal_linewidth functions?

Maybe this would be good for tidy developer day?

Thanks!

@davidhodge931 davidhodge931 changed the title Feature request: pal_size, pal_alpha, pal_linewidth, & pal_linewidth Feature request: pal_size, pal_alpha, & pal_linewidth Apr 15, 2024
@teunbrand
Copy link
Contributor

teunbrand commented Apr 16, 2024

I think these are all pal_rescale(). Colours, shapes and linetype have constraints on their output (e.g. must be valid col, pch and lty parameters). Size, alpha and linewidth all work with numerical values, so these have no such restraints and can all be fed through the pal_rescale() function. There is a pal_area() for the size though.

@davidhodge931
Copy link
Author

Thanks @teunbrand The use-case is mainly for something is reversed and you want to also reverse the other aesthetic to keep the order looking 'normal'. I can't work out how to use the pal_rescale() function to do this

library(tidyverse)
library(palmerpenguins)

p <- penguins |> 
  mutate(island = fct_rev(island)) |> 
  ggplot() +
  geom_point(aes(x = flipper_length_mm, 
                 y = island, 
                 size = island,
                 colour = island)) +
  scale_colour_manual(values = scales::pal_hue()(3)) +
  guides(colour = guide_legend(reverse = TRUE)) +
  guides(size = guide_legend(reverse = TRUE))

#I would like to be able to do this...
# p + 
#   scale_size_manual(values = scales::pal_size()(3))   

# I can't work out how to use scales::pal_rescale 
# p + 
#   scale_size_manual(values = scales::pal_rescale(range = c(1, 6))(3)) 

@teunbrand
Copy link
Contributor

Right, so it seems this is more about the difference between discrete and continuous palettes then?

@davidhodge931
Copy link
Author

I suppose I want to easily be able to recreate the default values for when things are reversed

@davidhodge931
Copy link
Author

Might not work so well with the discrete/continuous thing

Maybe I'll just close.. feel free to reopen if you want to do something with this

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

2 participants