ste*_*ffi 6 html r ggplot2 knitr
我使用knit将我的.Rhtml文件转换为.html文件.我正在调用一个名为Q1的块的输出:
<!--begin.rcode Q1,echo=FALSE,fig.show="all",fig.align="center",warning=FALSE
end.rcode-->
Run Code Online (Sandbox Code Playgroud)
这是块,它基本上是2x2布局中的ggplot2图.
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)))
Run Code Online (Sandbox Code Playgroud)
现在,当查看生成的html文件时,我想要包含以下功能:我希望在单击每个绘图的标题时有一个链接(例如,到数据库).这有点可能吗?
谢谢
这并不完全回答你的问题,但它可能会让你或其他人开始完整的答案.
Paul Murrel的gridSVG包(另请参阅这个有用的pdf文档)允许人们添加到基于网格的SVG图形的超链接.(理论上它应该适用于ggplot2 ;在实践中我只是使用了格子).R Journal的当前期刊包括一些文章("名称中有什么?"和"调试网格图形". - 警告:pdfs),可能有助于您最好地设计动态搜索您的grob名称我想添加一个链接(如我的第二行代码).
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")
Run Code Online (Sandbox Code Playgroud)