wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
655 stars 37 forks source link

Support for HTML links #16

Open jimhester opened 4 years ago

jimhester commented 4 years ago

It would be great if we could use <a href> or markdown links and they would be included as links when saving plots using SVG output. There are some existing solutions to this issue by modifying the produced SVG, but it seems more natural to do it with ggtext / gridtext.

library(ggplot2)
library(ggtext)
labels <- c(
  setosa = "<a href='https://en.wikipedia.org/wiki/Iris_setosa'>*I. setosa*</a>",
  virginica = "<a href='https://en.wikipedia.org/wiki/Iris_virginica'>*I. virginica*</a>",
  setosa = "<a href='https://en.wikipedia.org/wiki/Iris_versicolor'>*I. versicolor*</a>"
)

ggplot(iris, aes(Species, Sepal.Width)) +
  geom_boxplot() +
  scale_x_discrete(
    name = NULL,
    labels = labels
  ) +
  theme(
    axis.text.x = element_markdown(color = "black", size = 11)
  )
#> Error: gridtext has encountered a tag that isn't supported yet: <a>
#> Only a very limited number of tags are currently supported.

Created on 2020-02-06 by the reprex package (v0.3.0)

clauswilke commented 4 years ago

I agree. The problem is actually the graphics device. I don't think it's currently possible to push a link through an R graphics device.

The fundamental problem is that all I have at my disposal is elementary grid grobs, textGrob(), rectGrob(), etc. If something can't be done with those grobs I can't do it in gridtext.

jimhester commented 4 years ago

Yeah, I figured that might not be possible, makes sense.