Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dodge with pt.join #44

Merged
merged 5 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

### Bug fixes

- Fix missing "hypothesis" attribute for `aggr_es` objects (#43)
- Fix missing "hypothesis" attribute for `aggr_es` objects. (#43)
- Fix dodge misalignment between points and lines with multi fixest objects. (#44)

### Internals

- Replace `ggh4x` dependency with `legendry` (#41 @teunbrand)
- Replace `ggh4x` dependency with `legendry`. (#41 @teunbrand)

### Misc

Expand Down
31 changes: 18 additions & 13 deletions R/ggiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,23 @@ ggiplot = function(
has_groups = (!is.null(attributes(data)[["has_groups"]]) && isTRUE(attributes(data)[["has_groups"]]))
if (isTRUE(has_groups)) {

key <- unique(data[c("x", "group_var")])
key <- key[order(key[["group_var"]], key[["x"]]), , drop = FALSE]
xlimits <- as.character(key[["x"]])
key = unique(data[c("x", "group_var")])
key = key[order(key[["group_var"]], key[["x"]]), , drop = FALSE]
xlimits = as.character(key[["x"]])

rle <- rle(as.character(key[["group_var"]]))
keep <- nzchar(rle$values)
end <- cumsum(rle$lengths)
start <- end - rle$lengths + 1L
rle = rle(as.character(key[["group_var"]]))
keep = nzchar(rle$values)
end = cumsum(rle$lengths)
start = end - rle$lengths + 1L

key <- legendry::key_range_manual(
key = legendry::key_range_manual(
start = xlimits[start[keep]],
end = xlimits[end[keep]],
name = rle$values[keep],
level = 1L
)

data[["group_var"]] <- NULL
data[["group_var"]] = NULL
}

yrange = range(c(data[["ci_low"]], data[["ci_high"]]), na.rm = TRUE)
Expand Down Expand Up @@ -343,10 +343,15 @@ ggiplot = function(
if (geom_style == "ribbon" || pt.join) {
if (multi_style == "dodge") {
if (length(ci_level) == 1) {
geom_line(
aes(group = paste0(.data$group, .data$id)),
position = position_dodge(width = ci.width)
)
if (identical(data$group, data$id)) {
geom_line(position = position_dodge2(width = ci.width, padding = ci.width))
} else {
geom_line(
aes(group = paste0(.data$group, .data$id)), # catch for complex split combos
position = position_dodge2(width = ci.width, padding = ci.width)
)

}
} else {
geom_line(
data = ~ subset(.x, ci_level == max(ci_level)),
Expand Down
314 changes: 157 additions & 157 deletions inst/tinytest/_tinysnapshot/ggiplot_multi_complex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 53 additions & 53 deletions inst/tinytest/_tinysnapshot/ggiplot_multi_single_ribbon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
142 changes: 142 additions & 0 deletions inst/tinytest/_tinysnapshot/ggiplot_multi_sw_pt_join1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading