Giter VIP home page Giter VIP logo

Comments (3)

teunbrand avatar teunbrand commented on June 29, 2024 1

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.

japhir avatar japhir commented on June 29, 2024

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.

japhir avatar japhir commented on June 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.