Пользовательские цвета в ggplot2 subtitle feat. карандаш и клей
Я хотел бы создать субтитр с несколькими цветными словами в ggplot2. Мы можем использовать crayon::make_style, glue::glue и glue::glue_col, чтобы это произошло в консоли (см. Ниже). Однако при реализации в графическом устройстве цвет не отображается. Я просмотрел исходный код для подсказки, но не смог найти. Какие-нибудь мысли?
library(glue)
library(crayon)
library(tidyverse)
# create data frame
myDat <- tibble(alpha = rnorm(50),
omega = runif(50))
# use crayon to create our custom colors
slate_g <- crayon::make_style("slategrey")
light_s <- make_style("lightsalmon")
# create custom subtitle NOTE it prints cleanly in the console
cust_subt <- glue("
{str_wrap(\"It is a wonder that this subtitle is so dangerously long. Good thing we can wrap it in glue.\", 75)}
Really makes me wonder
{glue_col(\'{bold({slate_g(\"NEVER\")})} vs. {bold({light_s(\"ENOUGH\")})}\')}
")
Вот как cust_subt
объект печатает в консоли.
Как только мы пытаемся построить сюжет, он терпит неудачу.
# custom subtitle DOES NOT work in subtitle
ggplot(myDat, aes(alpha, omega)) +
geom_point() +
labs(subtitle = cust_subt)
#### regular glue works just fine though
cust_subt_no_col <- glue("
{str_wrap(\"It is a wonder that this subtitle is so dangerously long. Good thing we can wrap it in glue.\", 75)}
Really makes me wonder
")
ggplot(myDat, aes(alpha, omega)) +
geom_point() +
labs(subtitle = cust_subt_no_col)