What does autoplot.microbenchmark actually plot?
Asked Answered
C

1

21

According to the docs, microbenchmark:::autoplot "Uses ggplot2 to produce a more legible graph of microbenchmark timings."

Cool! Let's try the example code:

library("ggplot2")
tm <- microbenchmark(rchisq(100, 0),
                     rchisq(100, 1),
                     rchisq(100, 2),
                     rchisq(100, 3),
                     rchisq(100, 5), times=1000L)
autoplot(tm)

microbenchmark plots

I don't see anything about the...squishy undulations in the documentation, but my best guess from this answer by the function creator is that this is like a smoothed series of boxplots of the time taken to run, with the upper and lower quartiles connected over the body of the shape. Maybe? These plots look too interesting not to find out what is going on here.

What is this a plot of?

Chumley answered 27/6, 2014 at 12:12 Comment(0)
E
10

The short answer is a violin plot:

It is a box plot with a rotated kernel density plot on each side.


The longer more interesting(?) answer. When you call the autoplot function, you are actually calling

## class(ts) is microbenchmark
autoplot.microbenchmark

We can then inspect the actual function call via

R> getS3method("autoplot", "microbenchmark")
function (object, ..., log = TRUE, y_max = 1.05 * max(object$time)) 
{
    y_min <- 0
    object$ntime <- convert_to_unit(object$time, "t")
    plt <- ggplot(object, ggplot2::aes_string(x = "expr", y = "ntime"))
 ## Another ~6 lines or so after this

The key line is + stat_ydensity(). Looking at ?stat_ydensity you come to the help page on violin plots.

Excretion answered 18/9, 2016 at 10:13 Comment(1)
can you please take a look at my question? #65458835 thanksThroes

© 2022 - 2024 — McMap. All rights reserved.