1

I create a simple plot and have a picture actually an SVG icon as follows:

library(ggplot2); library(grid); library(gridExtra)

facebookGrob <- gTree(children=gList(pictureGrob(readPicture("inst/svg/facebook2.svg"))))

p1 <- ggplot() + 
  ggplot2::annotation_custom(facebookGrob, xmin=1.8, xmax=3.2, ymin=-0.6, ymax=1)

final <- arrangeGrob(p1,...,)
ggsave(filename='output.pdf',plot=final,...)

Is there any way to generate a clickable link on top of this SVG icon in the final PDF?

zx8754
  • 52,746
  • 12
  • 114
  • 209
SkyWalker
  • 13,729
  • 18
  • 91
  • 187

1 Answers1

2

the tikzDevice package lets you insert hyperref links as nodes,

library(tikzDevice)
tikz("annotation.tex",width=4,height=4, standAlone = TRUE,
     packages = c(getOption('tikzLatexPackages'),
                  "\\usepackage{hyperref}",
                  "\\usetikzlibrary{positioning}")
)

tg <- tikzNodeGrob(x = 0.5, y = 0.5, name = 'google',
             content='\\href{http://www.google.com}{\\includegraphics[width=1in]{google.png}}',
             units = "native")

qplot(1:10, 1:10) +
  annotation_custom(grob = tg, xmin=3,xmax=3,ymin=5,ymax=5)

dev.off()

enter image description here

baptiste
  • 75,767
  • 19
  • 198
  • 294
  • I get the following error `Measuring dimensions of: \char77 Error in system(latexCmd, intern = T, ignore.stderr = T) : error in running command` any ideas why it doesn't work for me? – SkyWalker Oct 22 '17 at 14:43