Skip to content

Commit c89c265

Browse files
authored
Ensure output is numeric even if ifelse clause is NA (#4692)
1 parent 74e1103 commit c89c265

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* `position_stack()` now works fully with `geom_text()` (@thomasp85, #4367)
4+
35
* `geom_tile()` now correctly recognises missing data in `xmin`, `xmax`, `ymin`,
46
and `ymax` (@thomasp85 and @sigmapi, #4495)
57

Diff for: R/position-stack.r

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ PositionStack <- ggproto("PositionStack", Position,
165165

166166
data$ymax <- switch(params$var,
167167
y = data$y,
168-
ymax = ifelse(data$ymax == 0, data$ymin, data$ymax)
168+
ymax = as.numeric(ifelse(data$ymax == 0, data$ymin, data$ymax))
169169
)
170170

171171
data <- remove_missing(
@@ -225,8 +225,8 @@ pos_stack <- function(df, width, vjust = 1, fill = FALSE) {
225225
ymin <- pmin(heights[-n], heights[-1])
226226
ymax <- pmax(heights[-n], heights[-1])
227227
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)
228+
df$ymin <- as.numeric(ifelse(max_is_lower, ymax, ymin))
229+
df$ymax <- as.numeric(ifelse(max_is_lower, ymin, ymax))
230230
df
231231
}
232232

0 commit comments

Comments
 (0)