tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.39k stars 2k forks source link

geom_sf_label() returns an error #5877

Closed kobetst closed 2 months ago

kobetst commented 2 months ago

Most probaly, the problem has occured after the last updates of ggplot2 package. I used ggplot2 almost daily, but the error started appearing just two days ago (in my case, within ggVennDiagram). A reproducible code with example data and the error is below. ggVennDiagram itself works fine, the problem is geom_sf_label(). Upgrade to R 4.4.0 and re-installation of ggplot2 (now ggplot2_3.5.1) didn't help.

reprex(input = "Example.R")

library(ggVennDiagram) library(ggplot2) x = list(A=1:5,B=2:7,C=3:6,D=4:9) ggVennDiagram(x) + geom_sf_label(mapping = aes(label = count), data = venn_region(process_data(Venn(x))))

> Error in geom_sf_label():

> ! Problem while computing aesthetics.

> ℹ Error occurred in the 5th layer.

> Caused by error in .data$X:

> ! Column X not found in .data.

rlang::last_trace() <error/rlang_error> Error in geom_sf_label(): ! Problem while computing aesthetics. ℹ Error occurred in the 5th layer. Caused by error in .data$X: ! Column X not found in .data.

Backtrace: ▆

  1. ├─base (local) <fn>(x)
  2. ├─ggplot2:::print.ggplot(x)
  3. │ ├─ggplot2::ggplot_build(x)
  4. │ └─ggplot2:::ggplot_build.ggplot(x)
  5. │ └─ggplot2:::by_layer(...)
  6. │ ├─rlang::try_fetch(...)
  7. │ │ ├─base::tryCatch(...)
  8. │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  9. │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
    1. │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
    2. │ │ └─base::withCallingHandlers(...)
    3. │ └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
    4. │ └─l$compute_aesthetics(d, plot)
    5. │ └─ggplot2 (local) compute_aesthetics(..., self = self)
    6. │ └─base::lapply(aesthetics, eval_tidy, data = data, env = env)
    7. │ └─rlang (local) FUN(X[[i]], ...)
    8. ├─X
    9. ├─rlang:::$.rlang_data_pronoun(.data, X)
    10. │ └─rlang:::data_pronoun_get(...)
    11. └─rlang:::abort_data_pronoun(x, call = y)
teunbrand commented 2 months ago

Hi there, thanks for the report. Can you give a minimal reproducible example using ggplot() and geom_sf_label()? In particular, can we eliminate ggVennDiagram() from this example, to make sure that the problem is with ggplot2 and not the ggVennDiagram package?

kobetst commented 2 months ago

Hi, you were right, and the actual problem was ggVennDiagram (ggplot exapmle without ggVennDiagram, but with geom_sf_label(), was OK). I found out that ggVennDiagram package has been also substantially remastered just recently, and stopped accepting geom_sf_label() function... Today I found and tried their new tutorial and got normal venn plots, as before. So, thanks a lot for the fast reply and your time!

teunbrand commented 2 months ago

I'm not sure how applicable this is, but when imposing new layers on a pre-existing plot where you don't have control over aesthetics etc, it might be best to use inherit.aes = FALSE to not mix up the aesthetics. As the problem appears to be related to ggVennDiagram, I think it is safe to close here.