exCon {exCon} | R Documentation |
Explore Contour Data Interactively
Description
These functions compute contour lines from matrix data and display them
in an interactive web page using the d3 javascript library. exCon
displays slices along the x and y directions. exCon2
does not
display the slices and is faster.
Usage
exCon(M = NULL, x = seq(0, 1, length.out = nrow(M)), y = seq(0, 1,
length.out = ncol(M)), nlevels = 5, levels = pretty(range(M, na.rm =
TRUE), nlevels), browser = NULL, minify = TRUE)
exCon2(M = NULL, x = seq(0, 1, length.out = nrow(M)), y = seq(0, 1,
length.out = ncol(M)), nlevels = 5, levels = pretty(range(M, na.rm =
TRUE), nlevels), browser = NULL, minify = TRUE)
Arguments
M |
A matrix. |
x |
A vector of numeric values giving the locations of the grid defining
the matrix. Must have length |
y |
A vector of numeric values giving the locations of the grid defining
the matrix. Must have length |
nlevels |
Integer. The number of contour levels desired. Ignored if |
levels |
Numeric. A vector of values (altitudes if you will) at which to compute the contours. |
browser |
Character. Something that will make sense to your OS. Only
necessary if you want to overide your system specified browser as understood by
|
minify |
Logical. Shall the JavaScript be minified? This improves
performance. However, it requires package |
Value
The path to the temporary directory containing the web page files. is returned invisibly. The side effect is an interactive web page. The temporary directory is deleted when you quit R, but you can use the return value to save the files to a different location.
Functions
-
exCon
: Interactive contour display with slices -
exCon2
: Interactive contour display without slices
Details
The computation of the contour lines is handled by
contourLines
. The result here, however, is transposed so that the
output has the same orientation as the original matrix. This is necessary because
contour
tranposes its output: "Notice that
contour
interprets the z
matrix as a table of
f(x[i], y[j])
values, so that the x axis corresponds to row number
and the y axis to column number, with column 1 at the bottom, i.e. a 90 degree
counter-clockwise rotation of the conventional textual layout."
Interpretation
The contour lines are an interpolation of the data
in the matrix. In exCon
, the slices are the actual values in the matrix
row or column
connected point-to-point. Thus a maximum in a slice may not correspond to
a peak in the contour plot.
Browser Choice
The browser is called by
browseURL
, which
in turn uses options("browser")
. Exactly how this is handled
is OS dependent.
Firefox Browser
the slices chosen and the values displayed are correct.
RStudio Viewer
If browser is NULL
, you are using RStudio,
and a viewer is specified, this will be called. You can stop this by with
options(viewer = NULL)
.
Browser Choice (Mac)
On a Mac, the default browser is called
by /bin/sh/open
which in turn looks at which browser you have set in the system settings. You can
override your default with
browser = "/usr/bin/open -a 'Google Chrome'"
for example.
Browser Choice & Performance
You can check the performance of your browser at peacekeeper.futuremark.com The most relevant score for exCon is the rendering category.
Performance Limits (YMMV)
On a early 2015 MacBook Pro, with 16 Gb RAM and an 2.9 GHz Intel Core i5 chip, a 1500 x 1500 matrix with 1 contour level requires about 15 seconds for R to render the web page using Chrome, Safari or Firefox. A 2K x 2K matrix appears to be too large to handle. R seems to hang during the handoff to the browser.
Examples
if (interactive()) {
require(jsonlite)
# minify is FALSE in the examples as not all platforms support the required pkgs (see above)
exCon(M = volcano, minify = FALSE)
exCon2(M = volcano, minify = FALSE) # no slices
# This next example will label the axes with the actual values, relative to the
# lower left corner (original data collected on 10 meter grid). Giving
# x and y affects only the scale, and the native values displayed at the top.
exCon(M = volcano, minify = FALSE,
x = seq(from = 0, by = 10, length.out = nrow(volcano)),
y = seq(from = 0, by = 10, length.out = ncol(volcano)))
}