Skip to content

geom_col does not render in facets in ggplot2 4.0.1 #6758

@MauricioCely

Description

@MauricioCely

Description:

In ggplot2 version 4.0.1, when using geom_col() in a facet_grid(), the plot panel for the second facet renders blank. This issue does not occur in ggplot2 version 4.0.0, where the same plot renders correctly. Replacing geom_col() with other geoms, like geom_point(), works as expected.

Steps to reproduce:

# Load necessary libraries
library(remotes)
library(fs)
library(tidyverse)
library(glue)

# Check the version of ggplot2 package in use
packageVersion('ggplot2')  
#> [1] '4.0.1'

# Prepare the data
df <- 
  airquality %>% 
  summarise(.by = c(Month, Day),
            Ozone = mean(Ozone),
            Temp = mean(Temp),
  ) %>% 
  mutate(date = glue("{Month}-{Day}-1973"),
         date = parse_date_time(date, 
                                "%m-%d-Y",
                                tz = "UTC")) %>% 
  select(-Month, -Day) %>% 
  pivot_longer(cols = -date) 

# Test plot with `ggplot2` version 4.0.1 where `geom_col` fails to render
ggplot(data = df,
       aes(
         x = date,
         y = value
       )) +
  facet_grid(name ~ ., scales = "free") +
  geom_line(data = \(x) filter(x, name == "Ozone")) +
  geom_col(data = \(x) filter(x, name == "Temp")) 
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf

# Test plot with `geom_point` instead of `geom_col` (this works fine)
ggplot(data = df,
       aes(
         x = date,
         y = value
       )) +
  facet_grid(name ~ ., scales = "free") +
  geom_line(data = \(x) filter(x, name == "Ozone")) +
  geom_point(data = \(x) filter(x, name == "Temp")) 

# Now, let's detatch the current `ggplot2` version and install version 4.0.0
detach("package:ggplot2")

# Create a new folder to install an older version of the package.
old_lib <- "~/old_lib/"

# Install the older version of ggplot2 (4.0.0)
install_version("ggplot2", version = "4.0.0", lib = old_lib)

# Load the older version of `ggplot2`
library("ggplot2", lib.loc = old_lib)
#> Overwriting method +(<ggplot2::ggplot>, <ANY>)
#> Overwriting method +(<ggplot2::theme>, <ANY>)
#> Overwriting method convert(<ggplot2::ggplot>, <list>)

# Check the version of `ggplot2` now
packageVersion("ggplot2")
#> [1] '4.0.0'

# Test plot again using ggplot2 version 4.0.0 (this should work as expected)
ggplot(data = df,
       aes(
         x = date,
         y = value
       )) +
  facet_grid(name ~ ., scales = "free") +
  geom_line(data = \(x) filter(x, name == "Ozone")) +
  geom_col(data = \(x) filter(x, name == "Temp")) 
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in min(x): no non-missing arguments to max; returning -Inf
#> Warning in min(d[d > tolerance]): no non-missing arguments to min; returning
#> Inf

reprex::reprex(session_info = TRUE)
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector

Created on 2025-11-25 with reprex v2.1.1

Session info

sessionInfo()
#> R version 4.5.2 (2025-10-31)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: America/New_York
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] ggplot2_4.0.0   glue_1.8.0      lubridate_1.9.4 forcats_1.0.1  
#>  [5] stringr_1.6.0   dplyr_1.1.4     purrr_1.2.0     readr_2.1.6    
#>  [9] tidyr_1.3.1     tibble_3.3.0    tidyverse_2.0.0 fs_1.6.6       
#> [13] remotes_2.5.0  
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.6       compiler_4.5.2     reprex_2.1.1       tidyselect_1.2.1  
#>  [5] xml2_1.5.0         clipr_0.8.0        dichromat_2.0-0.1  scales_1.4.0      
#>  [9] yaml_2.3.10        fastmap_1.2.0      R6_2.6.1           labeling_0.4.3    
#> [13] generics_0.1.4     curl_7.0.0         knitr_1.50         pillar_1.11.1     
#> [17] RColorBrewer_1.1-3 tzdb_0.5.0         rlang_1.1.6        stringi_1.8.7     
#> [21] xfun_0.54          S7_0.2.1           timechange_0.3.0   cli_3.6.5         
#> [25] withr_3.0.2        magrittr_2.0.4     digest_0.6.39      grid_4.5.2        
#> [29] rstudioapi_0.17.1  hms_1.1.4          lifecycle_1.0.4    vctrs_0.6.5       
#> [33] evaluate_1.0.5     farver_2.1.2       rmarkdown_2.30     tools_4.5.2       
#> [37] pkgconfig_2.0.3    htmltools_0.5.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorlayers 📈

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions