r - autoplot.microbenchmark 实际绘制了什么?

标签 r plot ggplot2 microbenchmark

根据文档,microbenchmark:::autoplot“使用 ggplot2 生成更清晰的微基准计时图表。”

酷!让我们尝试一下示例代码:

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

我在文档中没有看到任何关于......柔软的波动的信息,但我的最佳猜测来自 this answer by the function creator这就像一系列平滑的运行时间箱线图,上四分位数和下四分位数连接在形状的主体上。或许?这些情节看起来太有趣了,不去看看这里发生了什么。

这是一个什么情节?

最佳答案

简短的答案是 violin plot :

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

<小时/>

答案越长越有趣(?)。当您调用 autoplot 函数时,您实际上是在调用

## class(ts) is microbenchmark
autoplot.microbenchmark

然后我们可以通过检查实际的函数调用

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

关键行是+ stat_y密度()。看看?stat_y密度你 访问 fiddle 图的帮助页面。

关于r - autoplot.microbenchmark 实际绘制了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24451575/

相关文章:

将 ggplot 中的图例大小减小到超出默认大小

r - 整洁的评估编程和 ggplot2

r - Shiny 的多个动态过滤器更新

r - 如何获取 R 中 3 变量表的行百分比?

r - 当一个变量实际上是两列时 expand.grid

r - 如何在 R 和 ggplot2 中的背景图像上拟合绘图

r - 我如何将 ggplot2 colourbar 的宽度指定为面板宽度的一半?

r - 在 texreg 输出中包装自定义注释

python - Matplotlib 的内置区间图

r - 在 R 中使用 locator() 向绘图添加箭头