2013-04-29 76 views
0

這裏是產生模擬數據代碼:如何繪製相同的畫布上的兩條曲線中的R

eff = seq(.1, 1, .1) 
method = c('method1', 'method2') 
xxxd = expand.grid(eff=eff, method=method) 
xxxd$power = c(pow1, pow2) 
pow1 = seq(.2, .7, length.out=10) 
pow2 = seq(.4, .8, length.out=10) 
pow1 = pow1 + rnorm(10, .05, .01) 
pow2 = pow2 + rnorm(10, .05, .01) 
xxxd$power = c(pow1, pow2) 

這裏是數據:

eff method power 
1 0.1 method1 0.25942 
2 0.2 method1 0.32162 
3 0.3 method1 0.36329 
4 0.4 method1 0.41286 
5 0.5 method1 0.47904 
6 0.6 method1 0.52165 
7 0.7 method1 0.58191 
8 0.8 method1 0.64884 
9 0.9 method1 0.69488 
10 1.0 method1 0.73656 
11 0.1 method2 0.44882 
12 0.2 method2 0.49010 
13 0.3 method2 0.54465 
14 0.4 method2 0.58675 
15 0.5 method2 0.63173 
16 0.6 method2 0.69120 
17 0.7 method2 0.71456 
18 0.8 method2 0.77440 
19 0.9 method2 0.81033 
20 1.0 method2 0.85103 

,我想這個數字農產品是這樣的:

enter image description here

回答

3

由於您的數據似乎是在開始與長格式,它是瑣碎ggplot2使用:

library(ggplot2) 
ggplot(xxxd, aes(eff, power, colour = method)) + geom_line() 

enter image description here

爲GGPLOT2幫助頁面確實很精彩:http://docs.ggplot2.org/current/

+0

看起來非常優雅! – qed 2013-04-29 17:12:30

3

你可能想要做的lines()樂趣ction。首先使用plot()與您的「方法」之一,然後在第二個使用lines()。參數與plot相同。只是它將新曲線添加到現有繪圖而不是創建新窗口。 ?lines應該澄清更多。

+0

我如何用ggplot2或點陣來做到這一點? – qed 2013-04-29 16:49:46

相關問題