Skip to content

Commit

Permalink
Potentially improves Vincent's issue in #110
Browse files Browse the repository at this point in the history
  • Loading branch information
jthomasmock committed Feb 8, 2024
1 parent a3e3321 commit 639d68a
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions R/gt_plt_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,40 @@ gt_plt_dist <- function(gt_object,

if (isTRUE(same_limit)) {
if (is.null(bw)) {
bw <- 2 * stats::IQR(data_in, na.rm = TRUE) / length(data_in)^(1 / 3)
bw <- bw_calc(data_in)

} else {
bw <- bw
}

plot_out <- plot_base +
geom_histogram(
aes(x = .data$y),
color = line_color,
fill = fill_color,
binwidth = bw,
linewidth = 0.2
) +
scale_x_continuous(expand = expansion(mult = 0.2)) +
{
if(bw > 0){
geom_histogram(
aes(x = .data$y),
color = line_color, fill = fill_color, binwidth = bw,
linewidth = 0.2
)
} else if(bw == 0) {
bw <- 1

geom_histogram(
aes(x = .data$y),
color = line_color, fill = fill_color, binwidth = bw,
linewidth = 0.2
)
} else {

hist_breaks <- graphics::hist(data_in[!is.na(data_in)], breaks = "FD", plot=FALSE)$breaks

geom_histogram(
aes(x = .data$y),
color = line_color, fill = fill_color, breaks = hist_breaks,
linewidth = 0.2
)
}
} +
scale_x_continuous(expand = expansion(mult = 0.1)) +
coord_cartesian(
clip = "off",
xlim = grDevices::extendrange(
Expand Down

0 comments on commit 639d68a

Please sign in to comment.