[R] Can a hyperlink be placed, thorugh R programming, on a graph?
Jim Lemon
jim at bitwrit.com.au
Fri Apr 27 12:23:36 CEST 2007
Aldi Kraja wrote:
> Hi,
> If I use
>
> x<-1:10
> y<-rnorm(10,0,1)
> ### pdf(file="c:\\aldi\\test.pdf")
> plot(x,y)
> segments(x,y,x+2,y+2)
> segments(x,y,x+0.5,y+0.5,col=3)
> ### dev.off()
> ### q()
>
> Is there a way that I can imbed in the graph plot for each point defined
> by x to x+0.5 and y to y+0.5 (and colored in green) a different hyperlink?
>
> For example point one (together with the green tail) will have the
> hyperlink: www.r-project.org; point 2 with the link www.google.com;
> point 3 with the link www.yahoo.com etc.
>
> So in general, can the graph be manupulated within R?
>
Hi Aldi,
In HTML, the way to do this is usually known as an image map. Here is
one way to accomplish this.
png("aldi.png")
plot(x,y)
segments(x,y,x+2,y+2)
segments(x,y,x+0.5,y+0.5,col=3)
dev.off()
After generating the image in a format that will display on an HTML
page, create the page.
<html>
<head>
<title>HTML image map demo</title>
</head>
<body bgcolor="#abcdef">
<center>Click on one of the points to go to another URL</center><p>
<img src="aldi.png" width="480" height="480" usemap="#aldiplot"
align=center>
<map id="aldiplot" name="aldiplot">
<area shape="circle" coords="79,286,10" alt="P1"
href="http://www.r-project.org">
<area shape="circle" coords="119,77,10" alt="P2"
href="http://www.google.com">
<area shape="circle" coords="158,124,10" alt="P2"
href="http://www.yahoo.com">
</map>
</body>
</html>
Now if you point your browser at that HTML page, you should be able to
click on the first three points and be transferred to the URLs in your
example. Doing this in PDF should be pretty similar, but I don't know
how to write PDF code.
However, if you look at the code in either the R2HTML package or the
prettyR package, you can see how this could all be generated in R.
Jim
More information about the R-help
mailing list