Skip to content

Commit

Permalink
segplot: adjust for bar_space in secondary plot
Browse files Browse the repository at this point in the history
  • Loading branch information
elbersb committed Oct 30, 2023
1 parent c2d90f5 commit 3f977c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ segplot <- function(data, group, unit, weight,
checkmate::assert_choice(order, c("segregation", "entropy", "majority", "majority_fixed"))
checkmate::assert_choice(secondary_plot, c("segregation", "cumulative"), null.ok = TRUE)
checkmate::assert_data_frame(reference_distribution, ncols = 2, nrows = d[, uniqueN(group)], null.ok = TRUE)
checkmate::assert_numeric(bar_space, len = 1)
checkmate::assert_numeric(bar_space, len = 1, lower = 0)
checkmate::assert_character(hline, len = 1, null.ok = TRUE)

d[, unit := as.character(unit)]
Expand Down Expand Up @@ -171,7 +171,7 @@ segplot <- function(data, group, unit, weight,
label <- "Cumulative"
}

stat_segments_h <- wide[, .(unit, x = xmin, xend = xmax, y = stat, yend = stat)]
stat_segments_h <- wide[, .(unit, x = ifelse(.I == 1, xmin, xmin - bar_space), xend = xmax, y = stat, yend = stat)]
stat_segments_v <- wide[, .(unit, x = xmax, xend = xmax, y = stat, yend = shift(stat, type = "lead"))]
stat_segments <- rbindlist(list(stat_segments_h, stat_segments_v))
sub_plot <- ggplot2::ggplot(
Expand Down

0 comments on commit 3f977c2

Please sign in to comment.