0

How can I use fontawesome icons in my plot axes in ggplot? I've tried pasting it together with text and then converting it to html using htmltools, but it doesn't work.

Reproducible exmaple:


library(shiny)
library(tidyverse)


ui <- fluidPage(
  
  plotOutput("example")
 
)


server <- function(input, output) {
  output$example <- renderPlot({
    mtcars %>%
      ggplot(
        aes(
          x = wt,
          y = mpg,
          color = cyl
        )
      ) +
      geom_point() +
      labs(
        x = paste0("WT", icon("arrow-right")) %>% htmltools::HTML()
      )
  })
  
}


shinyApp(ui = ui, server = server)
anorlondo
  • 383
  • 1
  • 9
  • I don't think it's easily possible to add HTML to axis labels in this way. You could use Unicode symbols instead? _e.g._ `labs(x = "WT \u2192")`. – neilfws Aug 24 '23 at 01:03
  • See [How to add icons to ggplot captions and titles?](https://stackoverflow.com/questions/71712836/how-to-add-icons-to-ggplot-captions-and-titles/71717126#71717126) for an option using `showtext` which however requires to download the Fontawesome icons used by `shiny::icon`. – stefan Aug 24 '23 at 08:22

0 Answers0