[R] Does R have graphlets?
lsjensen
lsjensen at micron.com
Thu Oct 3 22:44:56 CEST 2002
This sample code creates a image map html file (similar to SPlus graphlets?)
that references a PNG file. Its not pretty but should give you some ideas to
make some simple R plots more web-interactive. You might need to change the
paths, etc to get it to work on your environment. Should be easy to wrap
this up in a more generic function.
Landon Jensen
Fab3 Parametrics/Integration
Micron Technology, Inc.
################
# data
x<-1:10
y<-rnorm(10)
#range of data
xmin<-min(x)
xmax<-max(x)
ymin<-min(y)
ymax<-max(y)
xdelta<-xmax-xmin
ydelta<-ymax-ymin
# pixel size of png plot
xsize<-600
ysize<-400
# define click zones (+/- pixels)
clickzones=5
# create png plot
png(file="/home/www/html/temp/imagemap.png",height=ysize,width=xsize)
par(mar=c(4,4,4,4))
plot(x,y)
usr<-par("usr")
plt<-par("plt")
dev.off()
# create mapping, active area coordinates
x1pixels<-clickzones
x2pixels<-clickzones
y1pixels<-clickzones
y2pixels<-clickzones
dataxmin<-usr[1]
dataxmax<-usr[2]
dataymin<-usr[3]
dataymax<-usr[4]
plotxmin<-plt[1]
plotxmax<-plt[2]
plotymin<-plt[3]
plotymax<-plt[4]
datawidth<-dataxmax-dataxmin
dataheight<-dataymax-dataymin
ratioxmin<-dataxmin/plotxmin
ratioxmax<-dataxmax/plotxmax
ratioymin<-dataymin/plotymin
ratioymax<-dataymax/plotymax
pixelxmin<-dataxmin*xsize/ratioxmin
pixelxmax<-dataxmax*xsize/ratioxmax
pixelymin<-dataymin*ysize/ratioymin
pixelymax<-dataymax*ysize/ratioymax
pixelwidth<-pixelxmax-pixelxmin
pixelheight<-pixelymax-pixelymin
AAC<-c()
for(i in 1:length(x)) {
x1<-(x[i]-dataxmin)/datawidth
x1<-x1*pixelwidth
x1<-floor(x1+pixelxmin + .5)
y1<-(1-(y[i]-dataymin)/dataheight)
y1<-y1*pixelheight
y1<-floor(y1+pixelymin + .5)
AAC<-c(AAC,paste((x1-x1pixels),",",(y1-y1pixels),",",(x1+x2pixels),",",(y1+y
2pixels),sep=""))
}
# create html file
write("<html><head><title>Image Map
Test</title></head><body>",file="/home/www/html/temp/imagemap.html")
write("<img src='imagemap.png' border=1 usemap='#imagemap.png'
ISMAP>",file="/home/www/html/temp/imagemap.html",append=TRUE)
write("<map
name='imagemap.png'>",file="/home/www/html/temp/imagemap.html",append=TRUE)
for(i in 1:length(x)) {
write(paste("<area coords='",AAC[i],"' alt='x=",x[i],",y=",y[i],"'
href='http://yelinux3.micron.com/temp/test.html'>",sep=""),file="/home/www/h
tml/temp/imagemap.html",append=TRUE)
}
write("</map></body>",file="/home/www/html/temp/imagemap.html",append=TRUE)
write("</html>",file="/home/www/html/temp/imagemap.html",append=TRUE)
################
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list