How to have a clickable picture in a PDF created using pictureGrob?

◇◆丶佛笑我妖孽 提交于 2019-12-08 12:04:32

问题


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?


回答1:


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()



来源:https://stackoverflow.com/questions/46227958/how-to-have-a-clickable-picture-in-a-pdf-created-using-picturegrob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!