The graph layout for which we want to create an image map.
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.
width
Width of the image.
height
Height of the image.
usr
Numeric vector of length 4. The user coordinates in the
plot window that object was plotted into.
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:
Create a graph layout with agopen
Plot it into a bitmap device, e.g. jpeg
or png.
Write HTML header.
Call the imageMap function.
Optionally, write further text into the HTML connection.
Close HTML file.
The new API for plotting of graphs now also allows for this
alternative procedure:
Lay out the graph object foo using
layoutGraph
render the graph on a bitmap device using
renderGraph like this:
foo <- renderGraph(foo)
Write HTML header.
Call the imageMap on the graph object foo.
Optionally, write further text into the HTML connection.
Close HTML file.
Value
The function is called for its side effect, which is writing text into
the connection con.
fhtml = paste(tempfile(), ".html", sep="")
fpng =paste(tempfile(), ".png", sep="")
if(capabilities()["png"] && interactive()) {
## Create a random graph, make tooltips and hyperlinks
set.seed(123)
g = randomEGraph(letters[14:22], 0.2)
tooltip = paste("This is node", nodes(g))
url = paste("This could be a link for node", nodes(g))
names(url) = names(tooltip) = nodes(g)
## Open plot device
width = height = 512
png(fpng, width=width, height=height)
par(mai=rep(0,4))
## Layout and render
lg = agopen(g, name="My layout")
plot(lg)
## Write an HTML file with the image map
con = file(fhtml, open="wt")
writeLines("<html><head><title>Click Me</title></head><body>\n", con)
imageMap(lg, con, fpng, tags=list(HREF=url, TITLE=tooltip), width=width, height=height)
writeLines("</body></html>", con)
close(con)
dev.off()
cat("Now have a look at file", fhtml, "with your browser.\n")
browseURL(fhtml)
}
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(biocGraph)
Loading required package: Rgraphviz
Loading required package: graph
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
Loading required package: grid
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/biocGraph/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,Ragraph-method
> ### imageMap,graph-method
> ### imageMap,Ragraph,connection,list,character-method
> ### imageMap,graph,connection,list,character-method
> ### Keywords: iplot
>
> ### ** Examples
>
> fhtml = paste(tempfile(), ".html", sep="")
> fpng =paste(tempfile(), ".png", sep="")
>
> #if(capabilities()["png"] && interactive()) {
>
> ## Create a random graph, make tooltips and hyperlinks
> set.seed(123)
> g = randomEGraph(letters[14:22], 0.2)
>
> tooltip = paste("This is node", nodes(g))
> url = paste("This could be a link for node", nodes(g))
> names(url) = names(tooltip) = nodes(g)
>
> ## Open plot device
> width = height = 512
> # png(fpng, width=width, height=height)
> par(mai=rep(0,4))
>
> ## Layout and render
> lg = agopen(g, name="My layout")
> plot(lg)
>
> ## Write an HTML file with the image map
> con = file(fhtml, open="wt")
> writeLines("<html><head><title>Click Me</title></head><body>\n", con)
>
> imageMap(lg, con, fpng, tags=list(HREF=url, TITLE=tooltip), width=width, height=height)
Warning messages:
1: '.local' is deprecated.
Use 'toFile' instead.
See help("Deprecated") and help("Rgraphviz-deprecated").
2: In .local(object, con, tags, imgname, ...) :
If par('mai') are not all 0, the result of this function (imageMap) may not be useful.
>
> writeLines("</body></html>", con)
> close(con)
> # dev.off()
>
> cat("Now have a look at file", fhtml, "with your browser.\n")
Now have a look at file /tmp/RtmpRYnbWD/file7ffb54ca0820.html with your browser.
> # browseURL(fhtml)
> #}
>
>
>
>
>
> dev.off()
null device
1
>