Aldi Kraja
2007-Apr-26 17:11 UTC
[R] Can a hyperlink be placed, thorugh R programming, on a graph?
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? TIA, Aldi
Aldi Kraja
2007-Apr-26 19:19 UTC
[R] Can a hyperlink be placed, thorugh R programming, on a graph?
Ok, Here is a simple solution: One can apply the text step (within a loop) for any other points and the hyperlinks are functional in the pdf format, and not viewable unless the mouse is over the link. If you have a better solution, let me know. x<-1:10 y<-rnorm(10,0,1) pdf(file="c:\\aldi\\test.pdf") plot(x,y) segments(x,y,x+2,y+2) text(x[3],y[3],c("http://www.r-project.org"),cex=0.1,col="white") segments(x,y,x+0.5,y+0.5,col=3) dev.off() Thanks, Aldi 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? > >TIA, > >Aldi > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. > >
Jim Lemon
2007-Apr-27 10:23 UTC
[R] Can a hyperlink be placed, thorugh R programming, on a graph?
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
Apparently Analagous Threads
- Plotting a broken line?
- "with" and "by" and NA:
- Error: cannot take a sample larger than the population
- Windows 7 R (32/64bit) running under cygwin: package not found
- How to protect two jobs running on the same directory at the same time not to corrupt each other results: