Skip to content

forestplot() fails or drops boxes when estimates are negative #73

@rempsyc

Description

@rempsyc

Description

When using forestplot() (version 3.1.7), the function behaves inconsistently when estimates are negative.

Specifically:

  1. When coefficients are made negative but CIs remain positive, the box is not drawn (only CI lines appear).
  2. When both coefficients and CIs are negative, the function throws an internal error:
Warning in min(cwidth[cwidth > 0], na.rm = TRUE):
  no non-missing arguments to min; returning Inf

Error in if (any(textHeight * (nrow(estimates) + 0.5) * 1.5 < boxsize)) :
  missing value where TRUE/FALSE needed
packageVersion("forestplot")
#> [1] '3.1.7'

library(forestplot)
#> Loading required package: grid
#> Loading required package: checkmate
#> Loading required package: abind

# A basic example, create some fake data
row_names <- list(list("test = 1", expression(test >= 2)))
test_data <- data.frame(
  coef = c(1.59, 1.24),
  low = c(1.4, 0.78),
  high = c(1.8, 1.55)
)
forestplot(test_data,
           labeltext = row_names,
           mean = coef,
           lower = low,
           upper = high)

# Make coefficient negative
test_data$coef <- test_data$coef * -1

forestplot(test_data,
           labeltext = row_names,
           mean = coef,
           lower = low,
           upper = high)

# Make CI negative
test_data$low <- test_data$low * -1
test_data$high <- test_data$high * -1

forestplot(test_data,
           labeltext = row_names,
           mean = coef,
           lower = low,
           upper = high)

#> Warning in min(cwidth[cwidth > 0], na.rm = TRUE): no non-missing arguments to
#> min; returning Inf
#> Error in `if (any(textHeight * (nrow(estimates) + 0.5) * 1.5 < boxsize)) ...`:
#> ! missing value where TRUE/FALSE needed

Created on 2026-02-24 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions