Title: | Interactive Exploration of Contour Data |
---|---|
Description: | Interactive tools to explore topographic-like data sets. Such data sets take the form of a matrix in which the rows and columns provide location/frequency information, and the matrix elements contain altitude/response information. Such data is found in cartography, 2D spectroscopy and chemometrics. The functions in this package create interactive web pages showing the contoured data, possibly with slices from the original matrix parallel to each dimension. The interactive behavior is created using the 'D3.js' 'JavaScript' library by Mike Bostock. |
Authors: | Bryan A. Hanson [aut, cre], Kristina R. Mulry [ctb], Mike Bostock [cph, ctb] (author of the d3.js library, http://d3js.org) |
Maintainer: | Bryan A. Hanson <[email protected]> |
License: | GPL-3 |
Version: | 0.2.5 |
Built: | 2024-11-19 03:54:25 UTC |
Source: | https://github.com/bryanhanson/excon |
exCon: Explore Contour Data Interactively
Interactive tools to explore topographic-like data sets. Such data sets take the form of a matrix in which the rows and contain altitude/response information. Such data is found in cartography, 2D spectroscopy and chemometrics. The functions in this package create interactive web pages showing the contoured data, possibly with slices from the original matrix parallel to each dimension. The interactive behavior is created using the D3.js 'JavaScript' library by Mike Bostock.
Bryan A. Hanson & Kristina R. Multry
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.
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)
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)
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 |
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.
exCon
: Interactive contour display with slices
exCon2
: Interactive contour display without slices
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."
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.
The browser is called by
browseURL
, which
in turn uses options("browser")
. Exactly how this is handled
is OS dependent.
the slices chosen and the values displayed are correct.
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)
.
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.
You can check the performance of your browser at peacekeeper.futuremark.com The most relevant score for exCon is the rendering category.
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.
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))) }
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))) }