R: Write an HTML IMG tag together with a MAP image map.
imageMap-methods
R Documentation
Write an HTML IMG tag together with a MAP image map.
Description
Write an HTML IMG tag together with a MAP image map.
Usage
## S4 method for signature 'matrix,connection,list,character'
imageMap(object, con, tags, imgname)
Arguments
object
Matrix with 4 columns, specifying the coordinates
of the mouse-sensitive region . Each row specifies the corners of a
rectangle within the image, in the following order: (left x,
lower y, right x, upper y). Note that the point (x=0, y=0) is
at the left upper side of the image.
con
Connection to which the image map is written.
tags
Named list whose elements are named character vectors.
Names must correspond to node names in object. See details.
imgname
Character. Name of the image file (for example PNG
file) that contains the plot.
Details
The most important tags are TITLE, HREF,
and TARGET. If the list tags contains an element
with name TITLE, then this must be a named character vector
containing the tooltips that are to be displayed when the mouse moves
over a node. The names of the nodes are specified in the names
attribute of the character vector and must match those of
object.
Similarly, HREF may be used to specify hyperlinks that the
browser can follow when the mouse clicks on a node, and TARGET
to specify the target browser window.
Currently, only rectangular regions are implemented; the actual
shape of the nodes as specified in object is ignored.
Also, tags for edges of the graph are currently not supported.
This function is typically used with the following sequence
of steps:
generate your graphic and save it as a bitmap file, e.g.
using the jpeg, png, or
bitmap device. At this stage, you also need to
figure out the pixel coordinates of the interesting regions
within your graphic. Since the mapping between device coordinates
and pixel coordinates is not obvious, this may be a little tricky.
See the examples below, and for a more complex example, see the
source code of the function plotPlate.
open an HTML page for writing and write HTML header,
e.g. using the openHtmlPage function.
Call the imageMap function.
Optionally, write further text into the HTML connection.
Close HTML file, e.g. using the closeHtmlPage function.
Value
The function is called for its side effect, which is writing text into
the connection con.
f1 = paste(tempfile(), ".html", sep="")
f2 = paste(tempfile(), ".html", sep="")
fpng = tempfile()
if(capabilities()["png"]) {
## create the image
colors = c("#E41A1C","#377EB8","#4DAF4A","#984EA3","#FF7F00","#FFFF33","#A65628","#F781BF","#999999")
width = 512
height = 256
png(fpng, width=width, height=height)
par(mai=rep(0,4))
plot(0,xlim=c(0,width-1),ylim=c(0,height-1),xaxs="i",yaxs="i",type="n",bty="n")
cx=floor(runif(100)*(width-11))
cy=floor(runif(100)*(height-11))
coord=cbind(cx, cy, cx+10, cy+10)
rect(coord[,1], height-coord[,2], coord[,3], height-coord[,4],
col=sample(colors, 100, replace=TRUE))
text(width/2, height-3, "Klick me!", adj=c(0.5, 1), font=2)
dev.off()
## create the frame set
cat("<html><head><title>Hello world</title></head>\n",
"<frameset rows="280,*" border="0">\n",
"<frame name="banner" src="file://", f2, "">\n",
"<frame name="main" scrolling="auto">",
"</frameset>", sep="",file=f1)
## create the image map
href =sample(c("www.bioconductor.org", "www.r-project.org"),nrow(coord),replace=TRUE)
title =sample(as.character(packageDescription("geneplotter")),nrow(coord),replace=TRUE)
con = file(f2, open="w")
imageMap(coord, con,
list(HREF=paste("http://", href, sep=""),
TITLE=title, TARGET=rep("main", nrow(coord))), fpng)
close(con)
cat("Now have a look at file ", f1, " with your browser.\n", sep="")
}
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(geneplotter)
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
rbind, rownames, sapply, setdiff, sort, table, tapply, union,
unique, unsplit
Welcome to Bioconductor
Vignettes contain introductory material; view with
'browseVignettes()'. To cite Bioconductor, see
'citation("Biobase")', and for packages 'citation("pkgname")'.
Loading required package: lattice
Loading required package: annotate
Loading required package: AnnotationDbi
Loading required package: stats4
Loading required package: IRanges
Loading required package: S4Vectors
Attaching package: 'S4Vectors'
The following objects are masked from 'package:base':
colMeans, colSums, expand.grid, rowMeans, rowSums
Loading required package: XML
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/geneplotter/imageMap.Rd_%03d_medium.png", width=480, height=480)
> ### Name: imageMap-methods
> ### Title: Write an HTML IMG tag together with a MAP image map.
> ### Aliases: imageMap imageMap-methods imageMap,matrix-method
> ### imageMap,matrix,connection,list,character-method
> ### Keywords: manip
>
> ### ** Examples
>
> f1 = paste(tempfile(), ".html", sep="")
> f2 = paste(tempfile(), ".html", sep="")
> fpng = tempfile()
>
> if(capabilities()["png"]) {
+ ## create the image
+ colors = c("#E41A1C","#377EB8","#4DAF4A","#984EA3","#FF7F00","#FFFF33","#A65628","#F781BF","#999999")
+ width = 512
+ height = 256
+ # png(fpng, width=width, height=height)
+ par(mai=rep(0,4))
+ plot(0,xlim=c(0,width-1),ylim=c(0,height-1),xaxs="i",yaxs="i",type="n",bty="n")
+ cx=floor(runif(100)*(width-11))
+ cy=floor(runif(100)*(height-11))
+ coord=cbind(cx, cy, cx+10, cy+10)
+ rect(coord[,1], height-coord[,2], coord[,3], height-coord[,4],
+ col=sample(colors, 100, replace=TRUE))
+ text(width/2, height-3, "Klick me!", adj=c(0.5, 1), font=2)
+ # dev.off()
+
+ ## create the frame set
+ cat("<html><head><title>Hello world</title></head>\n",
+ "<frameset rows="280,*" border="0">\n",
+ "<frame name="banner" src="file://", f2, "">\n",
+ "<frame name="main" scrolling="auto">",
+ "</frameset>", sep="",file=f1)
+
+ ## create the image map
+ href =sample(c("www.bioconductor.org", "www.r-project.org"),nrow(coord),replace=TRUE)
+ title =sample(as.character(packageDescription("geneplotter")),nrow(coord),replace=TRUE)
+ con = file(f2, open="w")
+ imageMap(coord, con,
+ list(HREF=paste("http://", href, sep=""),
+ TITLE=title, TARGET=rep("main", nrow(coord))), fpng)
+ close(con)
+
+ cat("Now have a look at file ", f1, " with your browser.\n", sep="")
+ }
Now have a look at file /tmp/RtmpLvXqZL/file700a482a7973.html with your browser.
>
>
>
>
>
> dev.off()
null device
1
>