Skip to content

Commit

Permalink
Ensure output is numeric even if ifelse clause is NA (#4692)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Dec 9, 2021
1 parent 74e1103 commit c89c265
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* `position_stack()` now works fully with `geom_text()` (@thomasp85, #4367)

* `geom_tile()` now correctly recognises missing data in `xmin`, `xmax`, `ymin`,
and `ymax` (@thomasp85 and @sigmapi, #4495)

Expand Down
6 changes: 3 additions & 3 deletions R/position-stack.r
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ PositionStack <- ggproto("PositionStack", Position,

data$ymax <- switch(params$var,
y = data$y,
ymax = ifelse(data$ymax == 0, data$ymin, data$ymax)
ymax = as.numeric(ifelse(data$ymax == 0, data$ymin, data$ymax))
)

data <- remove_missing(
Expand Down Expand Up @@ -225,8 +225,8 @@ pos_stack <- function(df, width, vjust = 1, fill = FALSE) {
ymin <- pmin(heights[-n], heights[-1])
ymax <- pmax(heights[-n], heights[-1])
df$y <- (1 - vjust) * ymin + vjust * ymax
df$ymin <- ifelse(max_is_lower, ymax, ymin)
df$ymax <- ifelse(max_is_lower, ymin, ymax)
df$ymin <- as.numeric(ifelse(max_is_lower, ymax, ymin))
df$ymax <- as.numeric(ifelse(max_is_lower, ymin, ymax))
df
}

Expand Down

0 comments on commit c89c265

Please sign in to comment.