Using knitr (from .Rhtml to html): how to insert a link in R?

I use knit to convert my .Rhtml file to a .html file. I call the output of piece Q1:

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

Here comes the piece, 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))) 

Now, looking at the received html file, I would like to include the following function: I would like to have a link (for example, to the database) when I click on the title of each plot. Is it possible?

thanks

+6
source share
1 answer

This does not fully answer your question, but may make you or someone else start with a complete answer.

Paul Murrell gridSVG package (see also this useful pdf document ) allows you to add hyperlinks to a grid based on SVG graphics. (Theoretically, it should work with ggplot2 , in practice I just worked with the grate ). The current issue of R magazine includes a couple of articles ( β€œWhat's in the name?” and β€œDebugging the graphics grid.” - Warning: pdf) that can help you best design a dynamic search for the grob name to which you want to add a link (how 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") 
+5
source

All Articles