2828# ' dataset (row) in `yrep`. For these plots `yrep` should therefore
2929# ' contain only a small number of rows. See the **Examples** section.
3030# ' }
31+ # ' \item{`ppc_qdotplot()`}{
32+ # ' A dot plot plot is displayed for `y` and each dataset (row) in `yrep`.
33+ # ' For these plots `yrep` should therefore contain only a small number of rows.
34+ # ' See the **Examples** section. This function requires [ggdist::stat_dots] to be installed.
35+ # ' }
3136# ' \item{`ppc_freqpoly_grouped()`}{
3237# ' A separate frequency polygon is plotted for each level of a grouping
3338# ' variable for `y` and each dataset (row) in `yrep`. For this plot
8085# ' ppc_pit_ecdf(y, yrep, prob = 0.99, plot_diff = TRUE)
8186# ' }
8287# '
83- # ' # for ppc_hist,dens,freqpoly,boxplot definitely use a subset yrep rows so
88+ # ' # for ppc_hist,dens,freqpoly,boxplot,qdotplot definitely use a subset yrep rows so
8489# ' # only a few (instead of nrow(yrep)) histograms are plotted
8590# ' ppc_hist(y, yrep[1:8, ])
8691# ' \donttest{
9095# ' # wizard hat plot
9196# ' color_scheme_set("blue")
9297# ' ppc_dens(y, yrep[200:202, ])
98+ # '
99+ # ' # dot plot
100+ # ' ppc_qdotplot(y, yrep[1:8, ])
93101# ' }
94102# '
95103# ' \donttest{
@@ -509,73 +517,8 @@ ppc_boxplot <-
509517
510518# ' @rdname PPC-distributions
511519# ' @export
520+ # ' @template args-qdotplot
512521ppc_qdotplot <-
513- function (y ,
514- yrep ,
515- ... ,
516- binwidth = NULL ,
517- freq = TRUE ) {
518- check_ignored_arguments(... )
519-
520- data <- ppc_data(y , yrep )
521-
522- # Calculate adaptive binwidth if not provided
523- if (is.null(binwidth )) {
524- data_range <- diff(range(data $ value , na.rm = TRUE ))
525- binwidth <- data_range / 30
526- }
527-
528- # Create a test plot to understand the data structure per facet
529- test_plot <- ggplot(data , aes(x = .data $ value )) +
530- geom_dotplot(
531- binwidth = binwidth ,
532- method = " histodot" ,
533- ) +
534- facet_wrap_parsed(" rep_label" )
535-
536- # Build the plot to extract scaling information
537- built_plot <- ggplot_build(test_plot )
538-
539- # Find the maximum count across all facets
540- max_count_per_facet <- built_plot $ data [[1 ]] %> %
541- group_by(PANEL ) %> %
542- summarise(max_count = max(count , na.rm = TRUE ), .groups = " drop" )
543- overall_max_count <- max(max_count_per_facet $ max_count , na.rm = TRUE )
544-
545- # More aggressive scaling for high counts
546- if (overall_max_count < = 9 ) {
547- optimal_dotsize <- 1.0
548- } else {
549- optimal_dotsize <- 3 / sqrt(overall_max_count )
550- }
551-
552- ggplot(data , mapping = set_hist_aes(
553- freq = freq ,
554- fill = !! quote(is_y_label ),
555- color = !! quote(is_y_label ),
556- )) +
557- geom_dotplot(
558- binwidth = binwidth ,
559- method = " histodot" ,
560- dotsize = optimal_dotsize ,
561- ) +
562- scale_fill_ppc() +
563- scale_color_ppc() +
564- facet_wrap_parsed(" rep_label" ) +
565- force_axes_in_facets() +
566- bayesplot_theme_get() +
567- space_legend_keys() +
568- yaxis_text(FALSE ) +
569- yaxis_title(FALSE ) +
570- yaxis_ticks(FALSE ) +
571- xaxis_title(FALSE ) +
572- facet_text(FALSE ) +
573- facet_bg(FALSE )
574- }
575-
576- # ## GGDIST VERSION
577- library(ggdist )
578- ppc_qdotplot_ggdist <-
579522 function (y ,
580523 yrep ,
581524 ... ,
@@ -584,14 +527,16 @@ ppc_qdotplot_ggdist <-
584527 freq = TRUE ) {
585528 check_ignored_arguments(... )
586529
530+ suggested_package(" ggdist" )
531+
587532 data <- ppc_data(y , yrep )
588533
589- ggplot(data , mapping = aes (
590- x = .data $ value ,
534+ ggplot(data , mapping = set_hist_aes (
535+ freq = freq ,
591536 fill = .data $ is_y_label ,
592537 color = .data $ is_y_label
593538 )) +
594- stat_dots(
539+ ggdist :: stat_dots(
595540 binwidth = binwidth ,
596541 quantiles = quantiles ,
597542 overflow = " warn"
0 commit comments