@@ -369,13 +369,25 @@ mcmc_nuts_treedepth <- function(x, lp, chain = NULL, ...) {
369369 yaxis_ticks(FALSE )
370370
371371 violin_lp_data <- data.frame (treedepth , lp = lp $ Value )
372+
373+ # Only keep treedepth values that occur more than once for violin plot
374+ value_counts <- table(violin_lp_data $ Value )
375+ keep_values <- names(value_counts [value_counts > 1 ])
376+ violin_lp_data <- violin_lp_data [violin_lp_data $ Value %in% keep_values , ]
377+
372378 violin_lp <-
373379 ggplot(violin_lp_data , aes(x = factor (.data $ Value ), y = .data $ lp )) +
374380 geom_violin(fill = get_color(" l" ), color = get_color(" lh" )) +
375381 labs(x = " treedepth__" , y = " lp__" ) +
376382 bayesplot_theme_get()
377383
378384 violin_accept_stat_data <- data.frame (treedepth , as = accept_stat $ Value )
385+
386+ # Only keep treedepth values that occur more than once for violin plot
387+ value_counts <- table(violin_accept_stat_data $ Value )
388+ keep_values <- names(value_counts [value_counts > 1 ])
389+ violin_accept_stat_data <- violin_accept_stat_data [violin_accept_stat_data $ Value %in% keep_values , ]
390+
379391 violin_accept_stat <-
380392 ggplot(violin_accept_stat_data , aes(x = factor (.data $ Value ), y = .data $ as )) +
381393 geom_violin(fill = get_color(" l" ), color = get_color(" lh" )) +
@@ -409,7 +421,6 @@ mcmc_nuts_treedepth <- function(x, lp, chain = NULL, ...) {
409421 as_bayesplot_grid(nuts_plot )
410422}
411423
412-
413424# ' @rdname MCMC-nuts
414425# ' @export
415426# ' @param alpha For `mcmc_nuts_energy()` only, the transparency (alpha) level
0 commit comments