Skip to content

Fix linetype regression #6097

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

Merged
merged 2 commits into from
Sep 16, 2024
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6096.

Briefly, it replaces na.value = "blank", which casts mapped value to characters, to na.value = NA, which will cast NA to whatever type mapped values have.

@yutannihilation
Copy link
Member

Looks good! I think this should be documented in NEWS.md as a (probably very minor) breaking change. IIUC, the following code was valid at v3.5.1. I think there are no or very little users who actually specify this, but just in case.

p + scale_linetype_manual(values = 1:5, na.value = "dotted")

@teunbrand
Copy link
Collaborator Author

teunbrand commented Sep 16, 2024

I'm happy to add a news bullet.

I'm not sure I agree it is a breaking change. In 3.5.1, using a numeric palette with character na.value also raises errors (if there are actual NAs to map). The only reason it is exposed now is because now append na.value to the palette here, so we always need to be able to cast na.value to the palette's type.

library(ggplot2)

df <- economics_long
df$variable[100:105] <- NA

ggplot(df, aes(date, value01, linetype = variable)) +
  geom_line() + 
  scale_linetype_manual(values = 1:5, na.value = "blank")
#> Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow): invalid line type: must be length 2, 4, 6 or 8

Created on 2024-09-16 with reprex v2.1.1

@yutannihilation
Copy link
Member

if there are actual NAs to map

Aw, got it. Sorry, I didn't notice this difference and tried with a data without actual NA. Thanks for the explanation, that makes sense!

@teunbrand teunbrand merged commit 842e6be into tidyverse:main Sep 16, 2024
13 checks passed
@teunbrand
Copy link
Collaborator Author

Thanks for the review!

@teunbrand teunbrand deleted the fix_linetype_regression branch September 16, 2024 09:13
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

Successfully merging this pull request may close these issues.

Regression in linetype scales
2 participants