Skip to content

Commit 3f9b3fd

Browse files
committed
avoid dividing by zero
1 parent 1bfb3c9 commit 3f9b3fd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

R/position-stack.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ pos_stack <- function(df, width, vjust = 1, fill = FALSE) {
224224
heights <- c(0, cumsum(y))
225225

226226
if (fill) {
227-
heights <- heights / abs(heights[length(heights)])
227+
total <- abs(heights[length(heights)])
228+
if (total > sqrt(.Machine$double.eps)) {
229+
heights <- heights / total
230+
}
228231
}
229232
# We need to preserve ymin/ymax order. If ymax is lower than ymin in input, it should remain that way
230233
if (!is.null(df$ymin) && !is.null(df$ymax)) {

0 commit comments

Comments
 (0)