2017-09-14 143 views
0

我创建了一个简单的情节和有他的照片实际上是一个SVG图标如下:如何在使用pictureGrob创建的PDF中创建可点击的图片?

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,...) 

有什么方法来生成最终的PDF这个SVG图标顶端有一个可点击的链接?

回答

2

的tikzDevice包可以让你插入hyperref宏链接为节点,

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

+0

我收到以下错误'测量的尺寸为:在系统\ char77 错误(latexCmd,实习生= T,忽视.stderr = T): 运行命令错误的任何想法为什么它不适合我? –