Skip to content

Issue with element_path() in {ggplot2} version 4.0.0 #24

@Josephhero

Description

@Josephhero

When I try to run ggpath::element_path() with a url to place a ggplot tag on my graphic, the code initially runs fine until I try to render the plot, at which point it spits out the cannot coerce error below. Prior to the updates to both {ggplot2} and {ggpath}, the below code ran fine. Now it is triggering an error.

Additionally, when trying to use nflplotR::element_nfl_logo() to replace the names of teams on the y axis of a bar chart, it now only deletes the team name text, but doesn't replace them with images.

``` r
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(nflreadr)
library(ggplot2)
library(nflplotR)
library(ggpath)
#> 
#> Attaching package: 'ggpath'
#> The following objects are masked from 'package:nflplotR':
#> 
#>     geom_from_path, geom_mean_lines, geom_median_lines

tag_url <- filter(load_teams(), team_abbr == "KC")$team_logo_espn[1] 
  
sched <- load_schedules(seasons = 2025) |> 
  filter(week == 6) 

plot_data <- sched |> 
  clean_homeaway() |> 
  select(team, team_score) 
  
plt <- ggplot(plot_data) +
  geom_col(aes(x = team_score, y = team)) +
  theme_minimal()

plt_logos <- plt +
  theme(
    axis.text.y.left = element_nfl_logo(),
  )

plt_logos
#> Error in grepl("tag", x = sys.calls()): cannot get a slot ("slots") from an object of type "NULL"

plt_tag <- plt +
  labs(tag = tag_url) +
  theme(
    plot.tag = ggpath::element_path(size = 5, hjust = 1, vjust = 1),
    plot.tag.position = c(1, 1), 
    plot.background = ggplot2::element_rect(fill = "#F0F0F0")
  )

plt_tag
#> Error in as.data.frame.default(x[[i]], optional = TRUE): cannot coerce class 'c("simpleUnit", "unit", "unit_v2")' to a data.frame



> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 14.5

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] ggpath_1.1.1   nflplotR_1.5.0 ggplot2_4.0.0  nflreadr_1.5.0 dplyr_1.1.4   

loaded via a namespace (and not attached):
 [1] pillar_1.11.1      compiler_4.2.3     RColorBrewer_1.1-3 tools_4.2.3        digest_0.6.37     
 [6] memoise_2.0.1      evaluate_1.0.5     lifecycle_1.0.4    tibble_3.3.0       gtable_0.3.6      
[11] pkgconfig_2.0.3    rlang_1.1.6        reprex_2.1.1       cli_3.6.5          rstudioapi_0.17.1 
[16] yaml_2.3.10        xfun_0.53          fastmap_1.2.0      withr_3.0.2        knitr_1.50        
[21] generics_0.1.4     vctrs_0.6.5        fs_1.6.6           grid_4.2.3         tidyselect_1.2.1  
[26] glue_1.8.0         data.table_1.17.8  R6_2.6.1           processx_3.8.6     rmarkdown_2.30    
[31] callr_3.7.6        farver_2.1.2       clipr_0.8.0        magrittr_2.0.4     ps_1.9.1          
[36] scales_1.4.0       htmltools_0.5.8.1  renv_1.0.7         labeling_0.4.3     S7_0.2.0          
[41] cachem_1.1.0      

Created on 2025-10-27 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