ggplot2
ggplot2 copied to clipboard
Improve message of `palette`/`na.value` mismatch
This is a spontaneous PR without a linked issue.
The current error message when using incompatible palette and na.value is confusing. It is unclear why na.value should have the character type.
library(ggplot2)
df <- mpg
df$drv[12] <- NA
ggplot(df, aes(displ, hwy, shape = drv)) +
geom_point() +
scale_shape_manual(
values = c("circle small", "triangle", "square"),
na.value = 4
)
#> Error in `vec_slice<-`:
#> ! Can't convert `na_value` <double> to <character>.
Created on 2025-12-08 with reprex v2.1.1
In this PR, it is more clear (it should match the palette type).
#> Error in `vec_assign()` at ggplot2/R/scale-.R:1343:7:
#> ! Can't convert `na.value` <double> to match type of `palette` <character>.