Skip to content

Commit a46260b

Browse files
committed
adding discrete argument to stat functions
1 parent e7d10d9 commit a46260b

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

R/ppc-test-statistics.R

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ ppc_stat <-
106106
yrep,
107107
stat = "mean",
108108
...,
109+
discrete = FALSE,
109110
binwidth = NULL,
110111
bins = NULL,
111112
breaks = NULL,
@@ -124,20 +125,32 @@ ppc_stat <-
124125
group = dots$group,
125126
stat = match.fun(stat)
126127
)
127-
ggplot(
128+
129+
graph <- ggplot(
128130
data = dplyr::filter(data, .data$variable != "y"),
129131
mapping = set_hist_aes(freq)
130-
) +
131-
geom_histogram(
132+
)
133+
134+
graph <- if (discrete) {
135+
graph + geom_bar(
136+
aes(fill = "yrep"),
137+
color = get_color("lh"),
138+
linewidth = 0.25,
139+
na.rm = TRUE,
140+
)
141+
} else {
142+
graph + geom_histogram(
132143
aes(fill = "yrep"),
133144
color = get_color("lh"),
134145
linewidth = 0.25,
135146
na.rm = TRUE,
136147
binwidth = binwidth,
137148
bins = bins,
138149
breaks = breaks
139-
) +
140-
geom_vline(
150+
)
151+
}
152+
153+
graph + geom_vline(
141154
data = dplyr::filter(data, .data$variable == "y"),
142155
mapping = aes(xintercept = .data$value, color = "y"),
143156
linewidth = 1.5
@@ -169,6 +182,7 @@ ppc_stat_grouped <-
169182
group,
170183
stat = "mean",
171184
...,
185+
discrete = FALSE,
172186
facet_args = list(),
173187
binwidth = NULL,
174188
bins = NULL,

R/ppd-test-statistics.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ppd_stat <-
3535
function(ypred,
3636
stat = "mean",
3737
...,
38+
discrete = FALSE,
3839
binwidth = NULL,
3940
bins = NULL,
4041
breaks = NULL,
@@ -51,18 +52,28 @@ ppd_stat <-
5152
group = dots$group,
5253
stat = match.fun(stat)
5354
)
54-
ggplot(data, mapping = set_hist_aes(
55+
graph <- ggplot(data, mapping = set_hist_aes(
5556
freq,
5657
color = "ypred",
5758
fill = "ypred"
58-
)) +
59+
))
60+
graph <- graph + if (discrete) {
61+
geom_bar(
62+
color = get_color("lh"),
63+
linewidth = 0.25,
64+
na.rm = TRUE,
65+
position = "identity",
66+
)
67+
}
68+
else {
5969
geom_histogram(
6070
linewidth = 0.25,
6171
na.rm = TRUE,
6272
binwidth = binwidth,
6373
bins = bins,
6474
breaks = breaks
65-
) +
75+
) }
76+
graph +
6677
scale_color_ppd(guide = "none") +
6778
scale_fill_ppd(labels = Typred_label(), guide = guide_legend(
6879
title = stat_legend_title(stat, deparse(substitute(stat)))
@@ -83,6 +94,7 @@ ppd_stat_grouped <-
8394
group,
8495
stat = "mean",
8596
...,
97+
discrete = FALSE,
8698
facet_args = list(),
8799
binwidth = NULL,
88100
bins = NULL,

man/PPC-test-statistics.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPD-test-statistics.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)