2015-04-04 39 views
1

我有幾個關於微基準和自動繪製R microbenchmark和autoplot?

問題想這是我的代碼:

library("ggplot2") 
tm <- microbenchmark(rchisq(100, 0),rchisq(100, 1),rchisq(100, 2),rchisq(100, 3),rchisq(100, 5), times=1000L) 
autoplot(tm) 
  1. 什麼是TM $時間單位?我怎麼能把它轉換成秒?
  2. 如何將x軸上的標記更改爲seq(from = 0,to = 100,by = 5)?

謝謝!

+0

真的應該每張貼在這裏有一個問題的方式.... – Spacedman 2015-04-04 17:49:10

回答

4

help(microbenchmark)給出:

1. ‘time’ is the measured execution time 
    of the expression in nanoseconds. 

納秒沒有毫秒或微秒。

所以除以1000000000轉換爲秒。

對於第二個問題,我的第一個回答是「爲什麼?」。但其ggplot爲主,這樣就可以通過添加ggplot東西覆蓋位:

autoplot(tm) + scale_y_log10(name="seq(whatever)") 

注意該地塊旋轉,使x軸爲y規模....

我剛以爲你真的是指「刻度線」?給定日誌軸,稍微不同但可行,但並不真正合適。可以強制非日誌軸與指定的刻度線:

autoplot(tm) + scale_y_continuous(breaks=seq(0,10000,len=5),name="not a log scale") 

你可以保持數標尺,並設置刻度點:

autoplot(tm) + scale_y_log10(breaks=c(50,200,500)) 
+0

謝謝。我今天也學到了一些新東西。好答案。 – LyzandeR 2015-04-04 17:53:08

+1

我以前沒見過autoplot,所以我也在學習! – Spacedman 2015-04-04 17:55:28