Comments (3)
The text layer has stat = "identity"
by default and any single layer is unaware of what is going on in other layers. As such, the error is appropriate. To use geom_text()
for labelling quantile-quantile statistics, you should add stat = "qq"
and maybe set a group. I just tried this, but it doesn't look great.
from ggplot2.
When I try the label gets dropped.
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.3.3
dat <- iris
dat |>
ggplot(aes(sample = Petal.Length)) +
geom_qq() +
geom_qq_line() +
geom_text(aes(label = Species,
x = after_stat(theoretical),
y = after_stat(sample)),
stat = "qq")
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?
#> Error in `geom_text()`:
#> ! Problem while setting up geom.
#> ℹ Error occurred in the 3rd layer.
#> Caused by error in `compute_geom_1()`:
#> ! `geom_text()` requires the following missing aesthetics: label.
#> Backtrace:
#> ▆
#> 1. ├─base::tryCatch(...)
#> 2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 3. │ ├─base (local) tryCatchOne(...)
#> 4. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 5. │ └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
#> 6. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 7. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 8. ├─base::withCallingHandlers(...)
#> 9. ├─base::saveRDS(...)
#> 10. ├─base::do.call(...)
#> 11. ├─base (local) `<fn>`(...)
#> 12. └─global `<fn>`(input = base::quote("sappy-tern_reprex.R"))
#> 13. └─rmarkdown::render(input, quiet = TRUE, envir = globalenv(), encoding = "UTF-8")
#> 14. └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
#> 15. └─knitr:::process_file(text, output)
#> 16. ├─base::withCallingHandlers(...)
#> 17. ├─base::withCallingHandlers(...)
#> 18. ├─knitr:::process_group(group)
#> 19. └─knitr:::process_group.block(group)
#> 20. └─knitr:::call_block(x)
#> 21. └─knitr:::block_exec(params)
#> 22. └─knitr:::eng_r(options)
#> 23. ├─knitr:::in_input_dir(...)
#> 24. │ └─knitr:::in_dir(input_dir(), expr)
#> 25. └─knitr (local) evaluate(...)
#> 26. └─evaluate::evaluate(...)
#> 27. └─evaluate:::evaluate_call(...)
#> 28. ├─evaluate (local) handle(...)
#> 29. │ └─base::try(f, silent = TRUE)
#> 30. │ └─base::tryCatch(...)
#> 31. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 32. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 33. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 34. ├─base::withCallingHandlers(...)
#> 35. ├─base::withVisible(value_fun(ev$value, ev$visible))
#> 36. └─knitr (local) value_fun(ev$value, ev$visible)
#> 37. └─knitr (local) fun(x, options = options)
#> 38. ├─base::withVisible(knit_print(x, ...))
#> 39. ├─knitr::knit_print(x, ...)
#> 40. └─knitr:::knit_print.default(x, ...)
#> 41. └─evaluate (local) normal_print(x)
#> 42. ├─base::print(x)
#> 43. └─ggplot2:::print.ggplot(x)
#> 44. ├─ggplot2::ggplot_build(x)
#> 45. └─ggplot2:::ggplot_build.ggplot(x)
#> 46. └─ggplot2:::by_layer(...)
#> 47. ├─rlang::try_fetch(...)
#> 48. │ ├─base::tryCatch(...)
#> 49. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 50. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 51. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 52. │ └─base::withCallingHandlers(...)
#> 53. └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
#> 54. └─l$compute_geom_1(d)
#> 55. └─ggplot2 (local) compute_geom_1(..., self = self)
#> 56. └─ggplot2:::check_required_aesthetics(...)
#> 57. └─cli::cli_abort(paste0(message, "."), call = call)
#> 58. └─rlang::abort(...)
from ggplot2.
Here is an example of how it could work:
library(ggplot2)
dat <- iris
dat |>
ggplot(aes(sample = Petal.Length, group = Species)) +
geom_qq() +
geom_qq_line() +
geom_text(aes(label = Species,
x = after_stat(theoretical),
y = after_stat(sample)),
stat = "qq")
Created on 2024-03-25 with reprex v2.1.0
In any case, this isn't a bug on ggplot2's behalf, so I'll close this issue.
from ggplot2.
Related Issues (20)
- Warnings due to partial matching HOT 2
- Reproducible example for `position_jitter()` not working HOT 1
- geom_sf_label() returns an error HOT 3
- date_breaks and date_breaks minor don't check argument type HOT 2
- `scale_*_*` `labels` argument often doesn't work as expected with a function HOT 8
- geom_histogram produces wrong number of bins in special cases HOT 2
- x/ylim Arguments in coord_fixed Don’t Seem to Be Applied to Contours: HOT 1
- Feature request: allow adding aesthetics together HOT 2
- Adding bootstrap customization for stat_summary(fun.data="mean_cl_boot") HOT 1
- Have header font be part of theme specification HOT 2
- Unexpected error about center/boundary in `geom_histogram()` when `bins = 1`
- ggplotly stopped working with version 3.5.1 HOT 3
- geom_tile -- Option to Split Diagonal Tiles. HOT 2
- Default labs where geom when the aesthetic is in both the ggplot and geom_* call HOT 1
- `stat_bin()` should have the area (instead of height) represent the count. HOT 3
- `ggplot2::ggpar()` has a namespace conflict with `ggpubr::ggpar()`
- Fallback for `facet_wrap(as.table)`
- Length check for `after_scale()` aesthetics HOT 1
- `geom_rug()` does not print a warning when `na.rm = FALSE` HOT 1
- Should the diamonds dataset factor variables be unorderd? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggplot2.