Comments (3)
I can reproduce the issue, though the benchmarks are measuring how long it takes to print(geom_area())
rather than how long it takes to render the plot :)
Here are more relevant benchmarks; for default options, geom_area()
takes 2 seconds whereas geom_ribbon()
takes 70 milliseconds.
library(ggplot2)
dat <- data.frame(
x = 1:1e4,
y = rnorm(1e4) + 5
)
area <- ggplot(dat) + geom_area(aes(x, y))
ribbon <- ggplot(dat) + geom_ribbon(aes(x, ymin = 0, ymax = y))
ragg::agg_png(tempfile(fileext = ".png"))
res <- bench::mark(
area = print(area),
ribbon = print(ribbon),
check = FALSE,
min_iterations = 5
)
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
print(res)
#> # A tibble: 2 × 13
#> expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time
#> <bch:expr> <bch:tm> <bch:> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm>
#> 1 area 2.02s 2.1s 0.469 129MB 16.7 5 178 10.7s
#> 2 ribbon 72.24ms 72.6ms 9.04 24.2MB 3.62 5 2 552.8ms
#> # ℹ 4 more variables: result <list>, memory <list>, time <list>, gc <list>
Both are about 70 milliseconds when stat and position are identity.
area <- ggplot(dat) +
geom_area(aes(x, y), stat = "identity", position = "identity")
ribbon <- ggplot(dat) +
geom_ribbon(aes(x, ymin = 0, ymax = y), stat = "identity", position = "identity")
res <- bench::mark(
area = print(area),
ribbon = print(ribbon),
check = FALSE,
min_iterations = 5
)
print(res)
#> # A tibble: 2 × 13
#> expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time
#> <bch:expr> <bch:tm> <bch:> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm>
#> 1 area 70.6ms 72.1ms 13.8 20.1MB 2.30 6 1 435ms
#> 2 ribbon 70.2ms 71.4ms 14.0 19.5MB 5.61 5 2 356ms
#> # ℹ 4 more variables: result <list>, memory <list>, time <list>, gc <list>
Created on 2024-03-21 with reprex v2.1.0
from ggplot2.
I guess the reason for this is the default position argument, which defaults to "identify" for ribbon and to stack for area, which may make it slow?
If I switch to:
dat |>
ggplot() +
geom_area(aes(x = x, y = y), position = "identity")
I seem to get the same speed.
Perhaps the function could check if there are any group or fill/colour aesthetics and if not, change the position argument to "identity"?
from ggplot2.
Nice work dude! Yeah I knew something was wrong in my benchmark, should have realized I could've just forced it to write to file ;-).
from ggplot2.
Related Issues (20)
- `scale_*_continuous` fails to render breaks if axis is reversed HOT 4
- When x values contain 0, using coord_trans("sqrt") removes the axis line HOT 4
- {marquee} integration HOT 1
- Encapsulate or export `{wrap/grid}_as_facets_list()`.
- ggplotly does not work when adding scale_fill_binned HOT 1
- Superfluous guidance in "Creating a new theme" section of ggplot2 packages vignette? HOT 2
- ggplot2 ignores the user's input for transparency via NA's in scale_fill_manual() HOT 12
- `guide_colorsteps()` can't set the `position` HOT 1
- strip.placement = "outside" and strip.switch.pad.wrap don't work together perfectly for facet_wrap. HOT 2
- `orientation` for `geom_step()` HOT 1
- Internal function `find_x_overlaps()` has bug
- layer code with geom = "rug" no longer works as expected in Development version
- stat_density() error and bw.nrd() man file are in conflict on valid inputs HOT 2
- binned_scale() function missing after version 3.4.1? HOT 1
- scale_y_discrete() fails without data to plot HOT 1
- Version 3.5.1 breaks passing of theme elements for ggplot2 extension HOT 4
- Feature request: radar/spider coordinate system HOT 10
- Feature request: non-rectangular panel clipping
- Inconsistent clipping of strip background depending on facets
- date-color handling default is inconsistent HOT 8
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.