Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to change the background color of texts in geom_textbox() #99

Open
moomoofarm1 opened this issue Dec 6, 2022 · 1 comment
Open

Comments

@moomoofarm1
Copy link

moomoofarm1 commented Dec 6, 2022

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
@clauswilke
Copy link
Collaborator

Yes, this is not possible, sorry. Only a very limited number of html features are supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants