Skip to content

Commit

Permalink
avoid error in a few cases when there are no divergences
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Dec 21, 2016
1 parent 814bb3d commit 6cec700
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: bayesplot
Type: Package
Title: Plotting for Bayesian Models
Version: 1.1.0
Date: 2016-12-19
Version: 1.1.0.9000
Date: 2016-12-21
Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"), email = "jsg2201@columbia.edu"),
person("Paul-Christian", "Buerkner", role = "ctb"))
Maintainer: Jonah Gabry <jsg2201@columbia.edu>
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
@@ -1,3 +1,12 @@
# bayesplot 1.1.0.9000

(GitHub issue/PR numbers in parentheses)

#### Fixes
* Avoid error in some cases when `divergences` specified in call to `mcmc_trace`
but there are not actually any divergent transitions.


# bayesplot 1.1.0

(GitHub issue/PR numbers in parentheses)
Expand All @@ -23,6 +32,7 @@ axis limits. (#59)
* The `stat` argument for all `ppc_stat_*` functions now accepts a function
instead of only the name of a function. (#31)


# bayesplot 1.0.0

* Initial CRAN release
25 changes: 16 additions & 9 deletions R/mcmc-traces.R
Expand Up @@ -250,14 +250,19 @@ mcmc_trace_highlight <-
graph <- graph +
scale_color_manual("Chain", values = chain_colors(n_chain))

if (!is.null(divergences))
graph <- graph +
divergence_rug(divergences, n_iter) +
guides(
color = guide_legend(order = 1),
linetype = guide_legend(order = 2, title = NULL, keywidth = rel(1/2),
override.aes = list(size = rel(1/2)))
)
if (!is.null(divergences)) {
div_rug <- divergence_rug(divergences, n_iter)
if (!is.null(div_rug))
graph <- graph +
div_rug +
guides(
color = guide_legend(order = 1),
linetype = guide_legend(order = 2,
title = NULL,
keywidth = rel(1/2),
override.aes = list(size = rel(1/2)))
)
}
}

facet_args$facets <- ~ Parameter
Expand Down Expand Up @@ -313,8 +318,10 @@ divergence_rug <- function(divergences, n_iter, color = "red", size = 1/4) {
divergences <- ifelse(divergences == 1, seq_along(divergences), NA)
div_info <- data.frame(Divergent = divergences)
}
if (all(is.na(div_info$Divergent)))
if (all(is.na(div_info$Divergent))) {
message("No divergences to plot.")
return(NULL)
}

geom_rug(
aes_(x = ~ Divergent, linetype = "Divergence"),
Expand Down

0 comments on commit 6cec700

Please sign in to comment.