2013-04-29 75 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

相关问题