You could do something like this:
library(ggplot2)
library(prismatic)
library(stringr)
blues <- grep("blue$", colors(), value = TRUE)
df <- data.frame(
name = blues,
str_len = str_length(blues)
)
ggplot(df, aes(x = str_len, y = name, label = str_len, fill = name)) +
geom_col() +
geom_text(
mapping = aes(
color = after_scale(best_contrast(fill, c("black", "white")))
),
hjust = 1,
nudge_x = -.25
) +
scale_fill_identity()