8000 Unable to change the background color of texts in geom_textbox() · Issue #99 · wilkelab/ggtext · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable to change the background color of texts in geom_textbox() #99
Open
@moomoofarm1

Description

@moomoofarm1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0