2014-06-27 34 views
10

根據文檔,microbenchmark:::autoplot「使用ggplot2生成一個更清晰的微基準標記時序圖。」autoplot.microbenchmark實際繪製了什麼?

酷!讓我們嘗試示例代碼:

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最好的猜測是,這就像一個平滑系列運行所需時間的箱形圖,上部和下部四分位連接在形狀的主體上。也許?這些情節看起來太有趣了,不知道這裏發生了什麼。

這是什麼情節?

回答

5

簡短的答案是violin plot

這是一個箱形圖在每邊旋轉的內核密度圖。


更長更有趣(?)的答案。當調用autoplot功能,你實際上是通過

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 

調用

## class(ts) is microbenchmark 
autoplot.microbenchmark 

然後,我們可以檢查實際的函數調用的關鍵行是+ stat_ydensity()。看?stat_ydensity你 來到小提琴劇情的幫助頁面。

相關問題