-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Convert linetype NA
s to blank lines
#6270
base: main
Are you sure you want to change the base?
Conversation
Does this change mean that the linetype legend guide now has a blank slot for NA values? That is not very telling if so |
It has a blank slot for NA values when there are NA values included in the scale limits/breaks, which by default occurs when there are NAs in the data. |
I guess this is a rare occurrence but it may catch users off-guard. I know this isn't really a fault of this PR but more a consequence of changing I think I'd feel better if |
The issue with I'm not sure I understand why having a blank linetype key would be undesirable? Is this not the correct behaviour? devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
df <- data.frame(x = 1:3)
ggplot(df, aes(x, xend = x + 1, y = x)) +
geom_segment(aes(linetype = c("A", "B", NA)))
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_segment()`). Created on 2025-01-28 with reprex v2.1.1 |
I just mean that the default in the scale constructor is All that being said, there are actual issues to having it blank as it completely removes the data. So you cannot see where the missing data supposedly is. But that is a whole other discussion and the ship has sailed on it I think |
So if I interpret this right, this is just about making sure the usage section in the documentation gives an interpretable value? If that is the case, I have a counterproposal. We remove |
I went ahead and implemented the linetype table idea. For the future, if anyone needs to replicate the figures, this is the code I used: df <- data.frame(
number = c(0:6),
num_display = c("0/NA", 1:6),
name = c('"blank"/NA', '"solid"', '"dashed"', '"dotted"', '"dotdash"', '"longdash"', '"twodash"'),
hex = c("", "", "\"44\"", "\"13\"", "\"1343\"", "\"73\"", "\"2262\"")
)
p <- ggplot(df, aes(x = 2, xend = 5, y = 6 - number)) +
geom_text(aes(x = 0, label = name), hjust = 0) +
geom_text(aes(x = -1, label = num_display), hjust = 0) +
geom_text(aes(x = 1, label = hex), hjust = 0) +
geom_segment(aes(linetype = I(number))) +
scale_x_continuous(
breaks = c(-1:2),
labels = c("Number", "Name", "Hex code", "Display"),
position = 'top'
) +
theme_void() +
theme(
axis.text.x.top = element_text(hjust = 0, size = 12, margin = margin_auto(10)),
plot.margin = margin_auto(5)
)
ggsave(
file.path("man", "figures", "linetype_table.svg"),
plot = p, device = svglite::svglite, fix_text_size = FALSE,
width = 6, height = 4, dpi = 72, bg = "white"
)
ggsave(
file.path("man", "figures", "linetype_table.pdf"),
plot = p,
width = 6, height = 4, dpi = 72, bg = "white"
) |
This PR aims to fix #6269.
Reprex from the issue; note no errors and no red outline:
Created on 2025-01-06 with reprex v2.1.1