Skip to content

Commit ee3cf49

Browse files
authored
Don't switch relationship of ymin/ymax during stacking (#3673)
1 parent 9f0fc2d commit ee3cf49

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

R/position-stack.r

+11-4
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,17 @@ pos_stack <- function(df, width, vjust = 1, fill = FALSE) {
216216
if (fill) {
217217
heights <- heights / abs(heights[length(heights)])
218218
}
219-
220-
df$ymin <- pmin(heights[-n], heights[-1])
221-
df$ymax <- pmax(heights[-n], heights[-1])
222-
df$y <- (1 - vjust) * df$ymin + vjust * df$ymax
219+
# We need to preserve ymin/ymax order. If ymax is lower than ymin in input, it should remain that way
220+
if (!is.null(df$ymin) && !is.null(df$ymax)) {
221+
max_is_lower <- df$ymax < df$ymin
222+
} else {
223+
max_is_lower <- rep(FALSE, nrow(df))
224+
}
225+
ymin <- pmin(heights[-n], heights[-1])
226+
ymax <- pmax(heights[-n], heights[-1])
227+
df$y <- (1 - vjust) * ymin + vjust * ymax
228+
df$ymin <- ifelse(max_is_lower, ymax, ymin)
229+
df$ymax <- ifelse(max_is_lower, ymin, ymax)
223230
df
224231
}
225232

0 commit comments

Comments
 (0)