使用knitr(从.Rhtml到html):如何在R图中嵌入链接? [英] Using knitr (from .Rhtml to html): how to embed a link in an R Figure?

查看:140
本文介绍了使用knitr(从.Rhtml到html):如何在R图中嵌入链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用knit将我的.Rhtml文件转换为.html文件。
我打电话给一个名为Q1的块输出:

I am using knit to convert my .Rhtml file to an .html file. I am calling the output of a chunk called Q1:

<!--begin.rcode Q1,echo=FALSE,fig.show="all",fig.align="center",warning=FALSE 
end.rcode--> 

这是块,它基本上是一个2x2布局的ggplot2图形。

Here comes the chunk, it is basically a ggplot2 figure in a 2x2 layout.

library(ggplot2)
myplot = list()
   for (i in 1:4){
          x = 1:100
          y = sample(100,100)
          data = data.frame(x=x,y=y)
          myplot[[i]] = ggplot(data,aes(x=x,y=y))+geom_point()+labs(title="bla")}

do.call(grid.arrange,c(myplot,list(nrow=2,ncol =2)))

现在,当查看生成的html文件时,我想要包含以下功能:
我想在点击每个图的标题时有一个链接(例如一个数据库)。
这是否有可能?

Now, when looking at the resulting html file, I would like to incorporate the following feature: I would like to have a link (e.g. to a database) when clicking on the title of each plot. Is this somehow possible?

Thx

Thx

推荐答案

这并不能完全回答你的问题,但它可能会让你或其他人开始一个完整的答案。

This doesn't completely answer your question, but it might get you or someone else started on a full answer.

Paul Murrel的 gridSVG (另见这个有用的pdf文档)允许将超链接添加到基于网格的SVG图形。 (理论上它应该与 ggplot2 一起使用;实际上我只是使用 lattice )。 R Journal杂志包括一些文章(什么是名字?和< a href =http://journal.r-project.org/archive/2012-2/RJournal_2012-2_Murrell+Ly.pdf =nofollow>调试网格图形。 - 警告: pdfs),这可能会帮助您最好地设计动态搜索您希望添加链接的grob名称(如在我的第二行代码中所述)。

Paul Murrel's gridSVG package (see also this useful pdf doc) allows one to add hyperlinks to grid-based SVG graphics. (In theory it should thus work with ggplot2; in practice I've just got it working with lattice). The current issue of the R Journal includes a couple of articles ("What's in a name?" and "Debugging grid graphics." -- Warning: pdfs) that might help you to best design dynamic searches for name of the grob to which you'd like to add a link (as in my second line of code).

library(gridSVG)
library(lattice)

xyplot(mpg~wt, data=mtcars, main = "Link to R-project home")
mainGrobName <- grep("main", grid.ls()[[1]], value=TRUE)
grid.hyperlink(mainGrobName, "http://www.r-project.org")
gridToSVG("HyperlinkExample.svg")

这篇关于使用knitr(从.Rhtml到html):如何在R图中嵌入链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆