Skip to content

Commit

Permalink
Merge branch 'develop' into roxygen-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
infotroph authored May 3, 2023
2 parents 5d15f35 + 5a5ddf5 commit 4bf8332
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
21 changes: 6 additions & 15 deletions modules/assim.batch/R/plot.da.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,10 @@ plot.da <- function(prior.dir, prior.file, in.dir, out.dir, next.run.dir) {
print(nrow(x))
print(length(good.runs))
for (i in seq_along(x)) {
trait.entry <- PEcAn.utils::trait.lookup(gsub("[1-2]$", "", traits[i]))
if (is.na(trait.entry)) {
trait.entry <- PEcAn.utils::trait.lookup(traits[i])
}

graphics::plot(x[good.runs, i], y[good.runs],
main = trait.entry$figid,
main = traits[i]$figid,
xlim = p.rng[i, ],
xlab = trait.entry$units,
xlab = traits[i]$units,
ylab = "-log(likelihood)",
pch = 1)
graphics::points(prior.x[, i], prior.y, col = "grey")
Expand Down Expand Up @@ -124,19 +119,15 @@ plot.da <- function(prior.dir, prior.file, in.dir, out.dir, next.run.dir) {
all <- do.call(rbind, lapply(samp, function(chain) chain[thin, i]))

# Density plots
trait.entry <- PEcAn.utils::trait.lookup(gsub("[1-2]$", "", traits[i]))
if (is.na(trait.entry)) {
trait.entry <- PEcAn.utils::trait.lookup(traits[i])
}
graphics::plot(stats::density(all),
xlim = p.rng[i, ],
main = paste(trait.entry$figid),
main = paste(traits[i]$figid),
type = "l",
ylab = "",
xlab = trait.entry$units)
xlab = traits[i]$units)
x <- seq(p.rng[i, 1], p.rng[i, 2], length = 1000)
graphics::lines(x, ddist(x, priors[traits[i], ]), col = "grey")
graphics::lines(x, ddist(x, priors2[traits[i], ]), col = "grey", lty = 2)
graphics::lines(x, ddist(x, priors[traits[i]$id, ]), col = "grey")
graphics::lines(x, ddist(x, priors2[traits[i]$id, ]), col = "grey", lty = 2)
}

# Now approximate posteriors to data assimilation and store them with posteriors from meta
Expand Down
20 changes: 9 additions & 11 deletions modules/priors/R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ plot_posterior.density <- function(posterior.density, base.plot = NULL) {
##' @title Prior Figure
##' @param priordata observations to be plotted as points
##' @param priordensity density of prior distribution, calculated by \code{\link{prior.density}}
##' @param trait name of trait
##' @param trait dataframe with id, figid and units of the trait
##' @param xlim limits for x axis
##' @author David LeBauer
##' @return plot / grob of prior distribution with data used to inform the distribution
##' @export
##' @importFrom ggplot2 ggplot aes theme_bw scale_x_continuous scale_y_continuous element_blank element_text geom_rug geom_line geom_point
priorfig <- function(priordata = NA, priordensity = NA, trait = "", xlim = "auto", fontsize = 18) {
priorfig <- function(priordata = NA, priordensity = NA, trait = NA, xlim = "auto", fontsize = 18) {
if (is.data.frame(priordata)) {
colnames(priordata) <- "x"
}
Expand All @@ -68,9 +68,9 @@ priorfig <- function(priordata = NA, priordensity = NA, trait = "", xlim = "auto
}

priorfigure <- ggplot() + theme_bw() +
scale_x_continuous(limits = xlim, breaks = x.breaks, name = PEcAn.utils::trait.lookup(trait)$units) +
scale_x_continuous(limits = xlim, breaks = x.breaks, name = trait$units) +
scale_y_continuous(breaks = NULL) +
labs(title = PEcAn.utils::trait.lookup(trait)$figid) +
labs(title = trait$figid) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(), ## hide y axis label
Expand Down Expand Up @@ -100,7 +100,7 @@ priorfig <- function(priordata = NA, priordensity = NA, trait = "", xlim = "auto
##--------------------------------------------------------------------------------------------------#
##' Plot trait density and data
##'
##' @param trait character, name of trait to be plotted
##' @param trait dataframe with id, figid and units of the trait to be plotted
##' @param prior named distribution with parameters
##' @param posterior.sample samples from posterior distribution
##' whose density should be plotted
Expand All @@ -119,7 +119,8 @@ priorfig <- function(priordata = NA, priordensity = NA, trait = "", xlim = "auto
##' parama = 20,
##' paramb = 5)
##' data1 <- data.frame(Y = c(19, 21), se = c(1,1))
##' plot_trait(trait = 'Vcmax',
##' trait1 <- data.frame(id = 'Vcmax', figid = 'Vcmax', units = 'umol CO2 m-2 s-1')
##' plot_trait(trait = trait1,
##' prior = prior1,
##' trait.df = data1)
##' }
Expand All @@ -143,9 +144,6 @@ plot_trait <- function(trait,
plot_prior <- !is.null(prior)
plot_data <- !is.null(trait.df)

## get units for plot title
units <- PEcAn.utils::trait.lookup(trait)$units

if(plot_data) trait.df <- PEcAn.MA::jagify(trait.df)

if (plot_prior) {
Expand Down Expand Up @@ -189,8 +187,8 @@ plot_trait <- function(trait,

trait.plot <- base.plot +
geom_segment(aes(x = min(x.ticks), xend = last(x.ticks), y = 0, yend = 0)) +
scale_x_continuous(limits = range(x.ticks), breaks = x.ticks, name = PEcAn.utils::trait.lookup(trait)$units) +
labs(title = PEcAn.utils::trait.lookup(trait)$figid) +
scale_x_continuous(limits = range(x.ticks), breaks = x.ticks, name = trait$units) +
labs(title = trait$figid) +
theme(axis.text.x = element_text(size = fontsize$axis),
axis.text.y = element_blank(),
axis.title.x = element_text(size = fontsize$axis),
Expand Down
5 changes: 3 additions & 2 deletions modules/priors/man/plot_trait.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions modules/priors/man/priorfig.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modules/priors/vignettes/priors_demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ vcmax.data <- vcmax.data[,c('ft', 'mean', 'se')]
prior.figures[['Vcmax']] <-
priorfig(priordensity = vcmax.density,
trait = 'Vcmax',
trait = dataframe(id = 'Vcmax', figid = 'Vcmax', units = 'umol CO2 m-2 s-1'),
xlim = range(c(0, max(vcmax.data$mean)))) +
geom_point(data = subset(vcmax.data, ft != 2),
aes(x=mean, y = (sum(vcmax.c4) + 1:sum(!vcmax.c4))/3000), color = 'grey60') +
Expand Down

0 comments on commit 4bf8332

Please sign in to comment.