Closed achafetz closed 3 months ago
@tessam30 I am using the code below to test under different options before applying to the package. I am missing something and not able to get any fill/color with 2 below?
library(palmerpenguins)
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
library(glitr)
data("penguins", package = "palmerpenguins")
penguins2 <- penguins %>%
mutate(species = na_if(species, "Gentoo"))
#1. default, no NA categories
penguins %>%
ggplot(aes(x = flipper_length_mm,
y = body_mass_g,
color = species,
shape = species)) +
geom_point(size = 3, alpha = 0.8, na.rm = TRUE) +
scale_color_si(palette = "hunter_d", discrete = TRUE) +
labs(title = "1. default") +
theme_minimal()
#2. when species has an NA value, color
penguins2 %>%
ggplot(aes(x = flipper_length_mm,
y = body_mass_g,
color = species,
shape = species)) +
geom_point(size = 3, alpha = 0.8, na.rm = TRUE) +
scale_color_si(palette = "hunter_d", discrete = TRUE, na.value = slate) +
labs(title = "2. species with NA, adjusting color") +
theme_minimal()
#3. when species has an NA value, fill + shape
penguins2 %>%
ggplot(aes(x = flipper_length_mm,
y = body_mass_g,
fill = species,
shape = species)) +
geom_point(size = 3, alpha = 0.8, na.rm = TRUE) +
scale_shape_manual(values = c("Adelie" = 21, "Chinstrap" = 24, "Gentoo" = 22),
na.value = 22) +
scale_fill_si(palette = "hunter_d", discrete = TRUE, na.value = slate) +
labs(title = "3. species with NA, adjusting fill + shape") +
theme_minimal()
#4. when species has an NA value, color + fill + shape
penguins2 %>%
ggplot(aes(x = flipper_length_mm,
y = body_mass_g,
fill = species, color = species,
shape = species)) +
geom_point(size = 3, alpha = 0.8, na.rm = TRUE) +
scale_shape_manual(values = c("Adelie" = 21, "Chinstrap" = 24, "Gentoo" = 22),
na.value = 22) +
scale_fill_si(palette = "hunter_d", discrete = TRUE, na.value = slate) +
scale_color_si(palette = "hunter_d", discrete = TRUE, na.value = slate) +
labs(title = "4. species with NA, adjusting color + fill + shape") +
theme_minimal()
Created on 2024-07-16 with reprex v2.1.1
When using
scale_color_si
orscale_fill_si
if the fill is based on a category that has aNA
value, it defaults to a gray fromscale_*_manual
that is too light,na.value = "gray50"
.We want to darken the value and keep within our palette by using
slate