Skip to content

Fix linetype regression - #6097

Merged
teunbrand merged 2 commits into
tidyverse:mainfrom
teunbrand:fix_linetype_regression
Sep 16, 2024
Merged

teunbrand merged 2 commits into
tidyverse:mainfrom
teunbrand:fix_linetype_regression

Conversation

@teunbrand

Copy link
Copy Markdown
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
Copy Markdown
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

teunbrand commented Sep 16, 2024 •

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
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
@teunbrand

Copy link
Copy Markdown
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