28
28
# ' dataset (row) in `yrep`. For these plots `yrep` should therefore
29
29
# ' contain only a small number of rows. See the **Examples** section.
30
30
# ' }
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
+ # ' }
31
36
# ' \item{`ppc_freqpoly_grouped()`}{
32
37
# ' A separate frequency polygon is plotted for each level of a grouping
33
38
# ' variable for `y` and each dataset (row) in `yrep`. For this plot
80
85
# ' ppc_pit_ecdf(y, yrep, prob = 0.99, plot_diff = TRUE)
81
86
# ' }
82
87
# '
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
84
89
# ' # only a few (instead of nrow(yrep)) histograms are plotted
85
90
# ' ppc_hist(y, yrep[1:8, ])
86
91
# ' \donttest{
90
95
# ' # wizard hat plot
91
96
# ' color_scheme_set("blue")
92
97
# ' ppc_dens(y, yrep[200:202, ])
98
+ # '
99
+ # ' # dot plot
100
+ # ' ppc_qdotplot(y, yrep[1:8, ])
93
101
# ' }
94
102
# '
95
103
# ' \donttest{
@@ -509,73 +517,8 @@ ppc_boxplot <-
509
517
510
518
# ' @rdname PPC-distributions
511
519
# ' @export
520
+ # ' @template args-qdotplot
512
521
ppc_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 <-
579
522
function (y ,
580
523
yrep ,
581
524
... ,
@@ -584,14 +527,16 @@ ppc_qdotplot_ggdist <-
584
527
freq = TRUE ) {
585
528
check_ignored_arguments(... )
586
529
530
+ suggested_package(" ggdist" )
531
+
587
532
data <- ppc_data(y , yrep )
588
533
589
- ggplot(data , mapping = aes (
590
- x = .data $ value ,
534
+ ggplot(data , mapping = set_hist_aes (
535
+ freq = freq ,
591
536
fill = .data $ is_y_label ,
592
537
color = .data $ is_y_label
593
538
)) +
594
- stat_dots(
539
+ ggdist :: stat_dots(
595
540
binwidth = binwidth ,
596
541
quantiles = quantiles ,
597
542
overflow = " warn"
0 commit comments