Title: | PEcAn visualization functions |
---|---|
Description: | The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific workflow management tool that is designed to simplify the management of model parameterization, execution, and analysis. The goal of PECAn is to streamline the interaction between data and models, and to improve the efficacy of scientific investigation. This module is used to create more complex visualizations from the data generated by PEcAn code, specifically the models. |
Authors: | Mike Dietze [aut], David LeBauer [aut, cre], Xiaohui Feng [aut], Dan Wang [aut], Carl Davidson [aut], Rob Kooper [aut], Shawn Serbin [aut], Alexey Shiklomanov [aut], Elizabeth Cowdery [aut], University of Illinois, NCSA [cph] |
Maintainer: | David LeBauer <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 1.8.0.9000 |
Built: | 2024-11-20 21:26:45 UTC |
Source: | https://github.com/PecanProject/pecan |
add_icon
add_icon(id = NULL, x = 0, y = 0)
add_icon(id = NULL, x = 0, y = 0)
id |
additional plot identification (URL, database ID, etc) |
x |
x-coordinate of logo |
y |
y-coordinate of logo |
Mike Dietze
plots a confidence interval around an x-y plot (e.g. a timeseries)
ciEnvelope(x, ylo, yhi, ...)
ciEnvelope(x, ylo, yhi, ...)
x |
Vector defining CI center |
ylo |
Vector defining bottom of CI envelope |
yhi |
Vector defining top of CI envelope |
... |
Further arguments passed on to |
Michael Dietze, David LeBauer
data.fetch
data.fetch(var, nc, fun = mean)
data.fetch(var, nc, fun = mean)
var |
the variable to extract from the hdf data |
nc |
ncdf file path |
fun |
the function to apply to the data at the same time, DEFAULT fun = mean |
aggregated data
When constructing a histogram, it is common to make all bars the same width. One could also choose to make them all have the same area. These two options have complementary strengths and weaknesses; the equal-width histogram oversmooths in regions of high density, and is poor at identifying sharp peaks; the equal-area histogram oversmooths in regions of low density, and so does not identify outliers. We describe a compromise approach which avoids both of these defects. We regard the histogram as an exploratory device, rather than as an estimate of a density.
dhist( x, a = 5 * iqr(x), nbins = grDevices::nclass.Sturges(x), rx = range(x, na.rm = TRUE), eps = 0.15, xlab = "x", plot = TRUE, lab.spikes = TRUE )
dhist( x, a = 5 * iqr(x), nbins = grDevices::nclass.Sturges(x), rx = range(x, na.rm = TRUE), eps = 0.15, xlab = "x", plot = TRUE, lab.spikes = TRUE )
x |
is a numeric vector (the data) |
a |
is the scaling factor, default is 5 * IQR |
nbins |
is the number of bins, default is assigned by the Stuges method |
rx |
is the range used for the left of the left-most bin to the right of the right-most bin |
eps |
used to set artificial bound on min width / max height of bins as described in Denby and Mallows (2009) on page 24 |
xlab |
is label for the x axis |
plot |
= TRUE produces the plot, FALSE returns the heights, breaks and counts |
lab.spikes |
= TRUE labels the % of data in the spikes |
list with two elements, heights of length n and breaks of length n+1 indicating the heights and break points of the histogram bars.
Lorraine Denby, Colin Mallows
Lorraine Denby, Colin Mallows. Journal of Computational and Graphical Statistics. March 1, 2009, 18(1): 21-31. doi:10.1198/jcgs.2009.0002.
Calculate interquartile range
iqr(x)
iqr(x)
x |
vector |
Calculates the 25th and 75th quantiles given a vector x; used in function dhist.
numeric vector of length 2, with the 25th and 75th quantiles of input vector x
Map Output
map.output(table, variable)
map.output(table, variable)
table |
data.table or data.frame with columns lat, lon, followed by variable names |
variable |
name of variable to be mapped |
plot
David LeBauer
Add data to an existing plot or create a new one
plot_data(trait.data, base.plot = NULL, ymax)
plot_data(trait.data, base.plot = NULL, ymax)
trait.data |
Data to be plotted |
base.plot |
a ggplot object (grob), created if none provided |
ymax |
maximum height of y |
Used to add raw data or summary statistics to the plot of a distribution. The height of Y is arbitrary, and can be set to optimize visualization. If SE estimates are available, the SE will be plotted
updated plot object
David LeBauer
## Not run: plot_data(data.frame(Y = c(1, 2), se = c(1,2)), base.plot = NULL, ymax = 10)
## Not run: plot_data(data.frame(Y = c(1, 2), se = c(1,2)), base.plot = NULL, ymax = 10)
Loads the tower data from an HDF5 file generated by ED and will plot the values against one another. The default is for the given variable to be plotted against time.
plot_netcdf( datafile, yvar, xvar = "time", width = 800, height = 600, filename = NULL, year = NULL )
plot_netcdf( datafile, yvar, xvar = "time", width = 800, height = 600, filename = NULL, year = NULL )
datafile |
the specific datafile to use. |
yvar |
the variable to plot along the y-axis. |
xvar |
the variable to plot along the x-axis, by default time is used. |
width |
the width of the image generated, default is 800 pixels. |
height |
the height of the image generated, default is 600 pixels. |
filename |
is the name of the file name that is generated, this can be null to use existing device, otherwise it will try and create an image based on filename, or display if x11. |
year |
the year this data is for (only used in the title). |
Rob Kooper
Add borders to plot
theme_border( type = c("left", "right", "bottom", "top", "none"), colour = "black", size = 1, linetype = 1 )
theme_border( type = c("left", "right", "bottom", "top", "none"), colour = "black", size = 1, linetype = 1 )
type |
border(s) to display |
colour |
what colo(u)r should the border be |
size |
relative line thickness |
linetype |
"solid", "dashed", etc. |
Has ggplot2 display only specified borders, e.g. ('L'-shaped) borders, rather than a rectangle or no border. Note that the order can be significant; for example, if you specify the L border option and then a theme, the theme settings will override the border option, so you need to specify the theme (if any) before the border option, as above.
adds borders to ggplot as a side effect
Rudolf Cardinal
## Not run: df = data.frame( x=c(1,2,3), y=c(4,5,6) ) ggplot(data=df, aes(x=x, y=y)) + geom_point() + theme_bw() + opts(panel.border = theme_border(c('bottom','left')) ) ggplot(data=df, aes(x=x, y=y)) + geom_point() + theme_bw() + opts(panel.border = theme_border(c('b','l')) ) ## End(Not run)
## Not run: df = data.frame( x=c(1,2,3), y=c(4,5,6) ) ggplot(data=df, aes(x=x, y=y)) + geom_point() + theme_bw() + opts(panel.border = theme_border(c('bottom','left')) ) ggplot(data=df, aes(x=x, y=y)) + geom_point() + theme_bw() + opts(panel.border = theme_border(c('b','l')) ) ## End(Not run)
Visually weighted regression / Watercolor plots
vwReg( formula, data, title = "", B = 1000, shade = TRUE, shade.alpha = 0.1, spag = FALSE, spag.color = "darkblue", mweight = TRUE, show.lm = FALSE, show.median = TRUE, median.col = "white", shape = 21, show.CI = FALSE, method = stats::loess, bw = FALSE, slices = 200, palette = (grDevices::colorRampPalette(c("#FFEDA0", "#DD0000"), bias = 2))(20), ylim = NULL, quantize = "continuous", add = FALSE, ... )
vwReg( formula, data, title = "", B = 1000, shade = TRUE, shade.alpha = 0.1, spag = FALSE, spag.color = "darkblue", mweight = TRUE, show.lm = FALSE, show.median = TRUE, median.col = "white", shape = 21, show.CI = FALSE, method = stats::loess, bw = FALSE, slices = 200, palette = (grDevices::colorRampPalette(c("#FFEDA0", "#DD0000"), bias = 2))(20), ylim = NULL, quantize = "continuous", add = FALSE, ... )
formula |
variables to plot. See examples |
data |
data frame containing all variables used in formula |
title |
passed on to ggplot |
B |
= number bootstrapped smoothers |
shade |
plot the shaded confidence region? |
shade.alpha |
should the CI shading fade out at the edges? (by reducing alpha; 0 = no alpha decrease, 0.1 = medium alpha decrease, 0.5 = strong alpha decrease) |
spag |
plot spaghetti lines? |
spag.color |
color of spaghetti lines |
mweight |
should the median smoother be visually weighted? |
show.lm |
should the linear regression line be plotted? |
show.median |
should the median smoother be plotted? |
median.col |
color of the median smoother |
shape |
shape of points |
show.CI |
should the 95% CI limits be plotted? |
method |
the fitting function for the spaghettis; default: loess |
bw |
= TRUE: define a default b&w-palette |
slices |
number of slices in x and y direction for the shaded region. Higher numbers make a smoother plot, but takes longer to draw. I wouldn'T go beyond 500 |
palette |
provide a custom color palette for the watercolors |
ylim |
restrict range of the watercoloring |
quantize |
either 'continuous', or 'SD'. In the latter case, we get three color regions for 1, 2, and 3 SD (an idea of John Mashey) |
add |
if add == FALSE, a new ggplot is returned. If add == TRUE, only the elements are returned, which can be added to an existing ggplot (with the '+' operator) |
... |
further parameters passed to the fitting function, in the case of loess, for example, 'span = .9', or 'family = 'symmetric” |
Idea: Solomon Hsiang, with additional ideas from many blog commenters Details: http://www.nicebread.de/visually-weighted-regression-in-r-a-la-solomon-hsiang/ http://www.nicebread.de/visually-weighted-watercolor-plots-new-variants-please-vote/
NULL plot as side effect
Felix Schönbrodt
# build a demo data set set.seed(1) x <- rnorm(200, 0.8, 1.2) e <- rnorm(200, 0, 3)*(abs(x)^1.5 + .5) + rnorm(200, 0, 4) e2 <- rnorm(200, 0, 5)*(abs(x)^1.5 + .8) + rnorm(200, 0, 5) y <- 8*x - x^3 + e y2 <- 20 + 3*x + 0.6*x^3 + e2 df <- data.frame(x, y, y2) p1 <- vwReg(y~x, df, spag=TRUE, shade=FALSE) p2 <- vwReg(y2~x, df, add=TRUE, spag=TRUE, shade=FALSE, spag.color='red', shape=3) p3 <- p1 + p2 p3 y <- x + x^2 + runif(200, 0, 0.4) vwReg(y ~ x, df, method=lm) vwReg(y ~ x + I(x^2), df, method=lm)
# build a demo data set set.seed(1) x <- rnorm(200, 0.8, 1.2) e <- rnorm(200, 0, 3)*(abs(x)^1.5 + .5) + rnorm(200, 0, 4) e2 <- rnorm(200, 0, 5)*(abs(x)^1.5 + .8) + rnorm(200, 0, 5) y <- 8*x - x^3 + e y2 <- 20 + 3*x + 0.6*x^3 + e2 df <- data.frame(x, y, y2) p1 <- vwReg(y~x, df, spag=TRUE, shade=FALSE) p2 <- vwReg(y2~x, df, add=TRUE, spag=TRUE, shade=FALSE, spag.color='red', shape=3) p3 <- p1 + p2 p3 y <- x + x^2 + runif(200, 0, 0.4) vwReg(y ~ x, df, method=lm) vwReg(y ~ x + I(x^2), df, method=lm)