It seems it is not currently possible to customize the country names on the legend, either by capitalization or full names.
library(ggflags)
# Capitalized country names don't work
d <- data.frame(
x = rnorm(10), y = rnorm(10),
country = sample(c("AR", "FR"), 10, TRUE),
stringsAsFactors = FALSE
)
ggplot2::ggplot(d, ggplot2::aes(x = x, y = y, country = country)) +
geom_flag() +
scale_country()
#> Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'grobify' for signature '"NULL"'
# Lower case works
p <- ggplot2::ggplot(d, ggplot2::aes(x = x, y = y, country = tolower(country))) +
geom_flag() +
scale_country()
p
# Specifying legend labels is ignored
p + ggplot2::scale_fill_discrete(labels = c("AR", "FR"))
p + ggplot2::scale_color_manual(labels = c("AR", "FR"))
p + ggplot2::scale_color_hue(labels = c("AR", "FR"))
It seems it is not currently possible to customize the country names on the legend, either by capitalization or full names.
Created on 2024-05-31 with reprex v2.1.0