Skip to content

Would scale_linewidth_discrete() be developed to set values manually like other scale_size_manual() #5050

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

Closed
ZhangSR-kolar opened this issue Nov 16, 2022 · 8 comments · Fixed by #5136
Labels
feature a feature request or enhancement scales 🐍

Comments

@ZhangSR-kolar
Copy link

Hi~

I'd like to ask, would the scale_linewidth() be developed to scale_linewidth_manual(), so that I can set the specific value to different levels when I use a factor variable to constrain linewidth, just as scale_size_manual()?

Thanks!

@ZhangSR-kolar ZhangSR-kolar changed the title Can scale_linewidth_discrete() be developed to set values manually like other *_manual() Would scale_linewidth_discrete() be developed to set values manually like other scale_size_manual() Nov 16, 2022
@MatthewHeun
Copy link

I've been wondering this, too. Maybe to put it another way,

data.frame(x = 1:10, y = 11:20, which = c(rep("a", 5), rep("b", 5))) %>% 
ggplot2::ggplot() + 
ggplot2::geom_line(mapping = ggplot2::aes(x = x, y = y, 
                                          colour = which, 
                                          size = which)) + 
ggplot2::scale_size_manual(values = c(a = 0.5, b = 5))

was a very convenient way to set size (linewidth) manually (and programmatically). Maybe I missed it, but I don't see an equivalent way to set linewidth manually. (If there is a way, please let us know!)

ggplot2::scale_linewidth_manual() would be very convenient.

@clauswilke
Copy link
Member

library(tidyverse)

data.frame(x = 1:10, y = 11:20, which = c(rep("a", 5), rep("b", 5))) %>% 
  ggplot() + 
  geom_line(aes(x, y, colour = which, linewidth = which)) + 
  scale_discrete_manual(aesthetic = "linewidth", values = c(a = 0.5, b = 5))

Created on 2022-11-20 by the reprex package (v2.0.1)

Note that I'm generally in favor of having manual scales for all aesthetics. When I wanted to add some a few years ago it was vetoed and the accepted solution was scale_discrete_manual().

@MatthewHeun
Copy link

```r
library(tidyverse)

data.frame(x = 1:10, y = 11:20, which = c(rep("a", 5), rep("b", 5))) %>% 
  ggplot() + 
  geom_line(aes(x, y, colour = which, linewidth = which)) + 
  scale_discrete_manual(aesthetic = "linewidth", values = c(a = 0.5, b = 5))

Created on 2022-11-20 by the reprex package (v2.0.1)
Note that I'm generally in favor of having manual scales for all aesthetics. When I wanted to add some a few years ago it was vetoed and the accepted solution was scale_discrete_manual().

This worked. I was unaware of scale_discrete_manual(). Thanks!

@teunbrand
Copy link
Collaborator

teunbrand commented Dec 30, 2022

Note that I'm generally in favor of having manual scales for all aesthetics.

I agree that that would make sense, but I can't find the counterarguments. I've seen a few times on SO that people were expecting scale_linewidth_manual() to exists.

@teunbrand
Copy link
Collaborator

In addition, scale_linewidth_identity() also doesn't exist.

@clauswilke
Copy link
Member

@teunbrand This is the relevant discussion:
#2555 (comment)

I think it was mostly a "let's defer this decision" rather than "let's not do this". It's probably time to revisit this.

@teunbrand teunbrand added this to the ggplot2 3.4.1 milestone Jan 5, 2023
@thomasp85
Copy link
Member

Both scale_linewidth_manual() and scale_linewidth_identity() has been omitted in error and should be added

@MatthewHeun
Copy link

Both scale_linewidth_manual() and scale_linewidth_identity() has been omitted in error and should be added

Thanks! That will be a big help to everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants