0

I am trying to display web links in a text box (as raw text). However, get an error (and I'm not an HTML expert, unfortunately). This there any way to reformat the web links so that they can be displayed as raw text within the text box? Thanks!

library(ggtext)
library(ggplot2)

test_data <- data.frame(x = 1,
                        y = 2,
                        text = "https://www.stackoverflow.com") 

ggplot(test_data, aes(x = x, y = y, label = text)) +
  geom_textbox()

#> Error: gridtext has encountered a tag that isn't supported yet: <a>
#> Only a very limited number of tags are currently supported.

Created on 2021-02-24 by the reprex package (v1.0.0)

Tee
  • 113
  • 1
  • 6
  • Possibly relevant: https://stackoverflow.com/questions/42259826/hyperlinking-text-in-a-ggplot2-visualization – teunbrand Feb 24 '21 at 10:28
  • Thanks, I will look into that. It is not about displaying hyperlinks though, but about displying links just as raw text inside the text box. – Tee Feb 24 '21 at 10:46

1 Answers1

0

I found a very simple solution. It works if you escape relevant characters using HTML entities.

library(ggtext)
library(ggplot2)

test_data <- data.frame(x = 1,
                        y = 2,
                        text = "https:&#47;&#47;www&#46;stackoverflow.com") 

ggplot(test_data, aes(x = x, y = y, label = text)) +
  geom_textbox(width = 0.6)

Created on 2021-02-24 by the reprex package (v1.0.0)

Tee
  • 113
  • 1
  • 6