-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feature request: layer_data
returns a tibble
#3018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So basically default to the wrapped output below, or am I missing something? library(tidyverse)
p <- ggplot(iris, aes(Species, Sepal.Length)) + geom_point()
layer_data <- as_tibble(ggplot2::layer_data(p))
layer_data
#> # A tibble: 150 x 10
#> x y PANEL group shape colour size fill alpha stroke
#> <int> <dbl> <fct> <int> <dbl> <chr> <dbl> <lgl> <lgl> <dbl>
#> 1 1 5.1 1 1 19 black 1.5 NA NA 0.5
#> 2 1 4.9 1 1 19 black 1.5 NA NA 0.5
#> 3 1 4.7 1 1 19 black 1.5 NA NA 0.5
#> 4 1 4.6 1 1 19 black 1.5 NA NA 0.5
#> 5 1 5 1 1 19 black 1.5 NA NA 0.5
#> 6 1 5.4 1 1 19 black 1.5 NA NA 0.5
#> 7 1 4.6 1 1 19 black 1.5 NA NA 0.5
#> 8 1 5 1 1 19 black 1.5 NA NA 0.5
#> 9 1 4.4 1 1 19 black 1.5 NA NA 0.5
#> 10 1 4.9 1 1 19 black 1.5 NA NA 0.5
#> # ... with 140 more rows Created on 2018-11-28 by the reprex package (v0.2.1.9000) |
Oh, yeah, I can convert the output to a I usually expect a |
No, it's not necessarily a bad idea, I just genuinely wanted to make sure I wasn't missing something! |
I think it is critical that @thomasp85 Would it be possible for your new |
I'm not sure how this affect the overall performance of ggplot2, but tibble seems slower than data.frame for subsetting by library(tibble)
d <- data.frame(a = 1, b = 2, c = 3)
t <- as_tibble(d)
m <- bench::mark(
"`[`, int, data.frame" = d[, 3, drop = FALSE],
"`[`, chr, data.frame" = d[, "c", drop = FALSE],
"`$`, data.frame" = d$c,
"`[[`, int, data.frame" = d[[3]],
"`[[`, chr, data.frame" = d[["c"]],
"`[`, int, tibble" = t[, 3],
"`[`, chr, tibble" = t[, "c"],
"`$`, tibble" = t$c,
"`[[`, int, tibble" = t[[3]],
"`[[`, chr, tibble" = t[["c"]],
check = FALSE
)
library(ggplot2)
autoplot(m) +
theme(axis.text.y = element_text(hjust = 0)) Created on 2018-11-30 by the reprex package (v0.2.1) |
Wow, |
Thanks for letting me know. We have a very expensive check and S3 dispatch which both slow down the code, but this is fairly easy to fix. Will do for the 2.0.0 release. |
Can subsetting for ints be made as fast as data.frame or will it remain ~10x slower? |
Let's discuss this on tidyverse/tibble#544 (or on a new issue on tibble's repo). |
Subsetting tibbles is now a tad faster on my machine for the use case shown here. |
Thanks, Kirill! @thomasp85 Can we now use tibbles internally in ggplot2? |
I’m unsure about any reason to doing this? Is the impediment simply so that layer_data returns a tibble? tibbles and data frames have very different sub setting behaviour so the change will likely require changes throughout the codebase |
I think the argument would be that all of tidyverse is moving/has moved to tibbles, so using them internally for ggplot2 would keep things consistent with the rest of the ecosystem. Also, apparently, now they're consistently faster (as the graphic above shows, almost by a factor of 10 for the most common use case, |
One more argument to support using tibble is that we are already using tibble's spec at least. NEWS says:
|
After a short discussion with @thomasp85 and @hadley, and since #3048 actually seems difficult, I'd concude that we cannot use tibble for internal uses; it's technically possible, but it requires a lot of work while the gain is relatively small. So, if we agree with this argument by @clauswilke, I will close this issue.
For a side note, I think it's good if we describe a concrete spec for internal data.frame. It's coincidently similar to |
I agree. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
I often use the
layer_
functions fromggplot2
for units tests. I was wondering if thelayer_data
function can return atibble
, which would make it much easier to peruse the data. Currently, this just overwhelms the console.Created on 2018-11-28 by the reprex package (v0.2.1)
The text was updated successfully, but these errors were encountered: