convertPlotCoordPix: Convert points of plot to coordinates in pixels

Description Usage Arguments Value See Also Examples

View source: R/convertPlotCoordPix.R

Description

This function allows conversion the plotting positions ('x' and 'y' coordiantes) of points in a given plot into coordiantes in pixels (of the entire plotting region). It was designed to be used as coordinates in an html file for mouse-over interactivity (display of names of points and links). Of course, the size of the plotting region is crucial and may not be changed afterwards (if the plot is not written to file using png etc). In turn the function mouseOverHtmlFile will use the pixel-coordiantes, allowing to annotate given points of a plot for mouse-over interactive html.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
convertPlotCoordPix(
  x,
  y,
  useMar = c(6.2, 4, 4, 2),
  plotDim = c(1400, 800),
  plotRes = 100,
  fromTop = TRUE,
  callFrom = NULL,
  silent = FALSE
)

Arguments

x

(numeric) initial plotting coordinates on x-axis, names of vector - if available- will be used as IDs

y

(numeric) initial plotting coordinates on y-axis

useMar

(numeric,length=4) margins defined with plot, see also par

plotDim

(integer, length=2) dimension of the plotting device in pixels, see also par

plotRes

(integer) resoltion of plotting device, see also par

fromTop

(logical) toggle if poordinates should start from top

callFrom

(character) allow easier tracking of message(s) produced

silent

(logical) suppress messages

Value

matrix with x- and y-coordinates in pixels

See Also

mouseOverHtmlFile

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
df1 <- data.frame(id=letters[1:10],x=1:10,y=rep(5,10),mou=paste("point",letters[1:10]),
  link=file.path(tempdir(),paste(LETTERS[1:10],".html",sep="")),stringsAsFactors=FALSE)  
## Typically one wants to get pixel-coordinates for plots written to file.
## Here we'll use R's tempdir, later you may want to choose other locations
pngFile <- file.path(tempdir(),"test01.png")
png(pngFile,width=800, height=600,res=72)
## here we'll just plot a set of horiontal points at default parameters ...
plot(df1[,2:3],las=1,main="test01")
dev.off()
## Note: Special characters should be converted for proper display in html during mouse-over
library(wrMisc)
df1$mou <- htmlSpecCharConv(df1$mou)
## Let's add the x- and y-coordiates of the points in pixels to the data.frame
df1 <- cbind(df1,convertPlotCoordPix(x=df1[,2],y=df1[,3],plotD=c(800,600),plotRes=72))
head(df1)
## using mouseOverHtmlFile() one could now make an html document with interactive 
## display of names and clockable links to the coordinates we determined here ...

Example output

png 
  2 
 ->  convertPlotCoordPix : supl params : mar=6.2,4,4,2  dim=800x600   res=72
  id x y     mou                            link xPix yPix
1  a 1 5 point a /work/tmp/tmp/Rtmp9kDCsa/A.html   81  284
2  b 2 5 point b /work/tmp/tmp/Rtmp9kDCsa/B.html  155  284
3  c 3 5 point c /work/tmp/tmp/Rtmp9kDCsa/C.html  229  284
4  d 4 5 point d /work/tmp/tmp/Rtmp9kDCsa/D.html  303  284
5  e 5 5 point e /work/tmp/tmp/Rtmp9kDCsa/E.html  377  284
6  f 6 5 point f /work/tmp/tmp/Rtmp9kDCsa/F.html  451  284

wrGraph documentation built on April 12, 2021, 1:07 a.m.