如何在带有R的pdf中插入可点击链接

Att*_*cus 11 pdf pdf-generation r

我用R pdf()函数保存了一个用R生成的图(见下文).是否可以在此图中添加可点击的超链接?pdf()欢迎替代方案.

pdf(file="plot.pdf",width=20,height=50)
q <- ggplot(df, aes(x=reorder(desc,Value, FUN=median), y=Value))
q + geom_boxplot(aes(fill = factor(role)))+ coord_flip()
dev.off()
Run Code Online (Sandbox Code Playgroud)

其中,df$desc如下所示:

[1] "http://www.jcvi.org/cgi-bin/tigrfams/HmmReportPage.cgi?acc=TIGR02914  #  EpsI_fam: EpsI family protein  # Role: 141"                                        
[2] "http://www.jcvi.org/cgi-bin/tigrfams/HmmReportPage.cgi?acc=TIGR03067  #  Planc_TIGR03067: Planctomycetes uncharacterized domain TIGR03067  # Role: 157"     
[3] "http://www.jcvi.org/cgi-bin/tigrfams/HmmReportPage.cgi?acc=TIGR03021  #  pilP_fam: type IV pilus biogenesis protein PilP  # Role: 91"   
Run Code Online (Sandbox Code Playgroud)

在pdf中,链接不可点击.

小智 3

您可以使用 Rsweave 来做到这一点。Rsweave 允许您从 LaTeX 中调用 R。

因此,使用我自己编写的数据的示例文件将是:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\SweaveOpts{concordance=TRUE}


<<echo=FALSE,fig=TRUE>>=
    library(ggplot2)
    q <- ggplot() + geom_point(data=data.frame(x = c(1,2,3,4),y=c(4,3,2,1)), aes(x=x,y=y))
    print(q)
@
\par{
    \url{http://google.com}
}

\end{document}
Run Code Online (Sandbox Code Playgroud)

您可以从 Rstudio 编译它。如果文件具有 .rnw 扩展名,它将知道该怎么做。如果您从 R 进行编译,则可以使用 Sweave 命令。