convertPlotCoordPix {wrGraph} | R Documentation |
Convert points of plot to coordinates in pixels
Description
This function allows conversion the plotting positions ('x' and 'y' coordinates) of points in a given plot into coordinates 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-coordinates, allowing to annotate given points of a plot for mouse-over interactive html.
Usage
convertPlotCoordPix(
x,
y,
useMar = c(6.2, 4, 4, 2),
plotDim = c(1400, 800),
plotRes = 100,
fromTop = TRUE,
callFrom = NULL,
silent = FALSE,
debug = 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 |
plotDim |
(integer, length=2) dimension of the plotting device in pixels, see also |
plotRes |
(integer) resoltion of plotting device, see also |
fromTop |
(logical) toggle if poordinates should start from top |
callFrom |
(character) allows easier tracking of messages produced |
silent |
(logical) suppress messages |
debug |
(logical) additonal messages for debugging |
Value
matrix with x- and y-coordinates in pixels
See Also
Examples
df1 <- data.frame(id=letters[1:10], x=1:10, y=rep(5,10),mou=paste("point",letters[1:10]),
link=file.path(tempdir(),paste0(LETTERS[1:10],".html")), 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 ...