I want to change the background color of texts using the HTML tag . But the generated plot does not seem to support the tag here.
The text "Fuel economy" should have a background color with the color code "#F7D1CD". But the background color of the text "Fuel economy" in the output plot is now with the color code "#37FAB6".
library(ggplot2)
library(ggtext)
colorSent <- "#37FAB6"
sent <- "<span style = 'background-color:#F7D1CD'>Fuel economy </span> vs. engine displacement"
df <- data.frame(
label = sent,
x = c(0.5),
y = c(0.5),
hjust = c(0.5), vjust = c(0.5),
fill = c(colorSent)
)
p <- ggplot2::ggplot() + ggplot2::theme_void() +
ggplot2::aes(
x, y,
label = label,
fill = fill,
hjust = hjust, vjust = vjust
) + ggtext::geom_textbox(data=df) +
ggplot2::scale_discrete_identity(aesthetics = c("fill" )) +
ggplot2::xlim(0, 1) + ggplot2::ylim(0, 1) +
ggplot2::theme(plot.background = ggplot2::element_rect(fill="#FCCB58"))
p
I want to change the background color of texts using the HTML tag . But the generated plot does not seem to support the tag here. The text "Fuel economy" should have a background color with the color code "#F7D1CD". But the background color of the text "Fuel economy" in the output plot is now with the color code "#37FAB6".