作者celestialgod (天)
看板Statistics
标题Re: [程式] R x座标略不同如何画在同张图上
时间Mon Oct 19 12:36:15 2015
xlim = apply(abs(cbind(range(x1), range(x2))),1,max) * sign(range(x1))
plot(x1, y1, type = "l", xlim = xlim)
par(new=TRUE)
plot(x2, y2, type = "l", col = "blue", xlim = xlim)
PS: 如果range(x1)有0 这方法会fail (在sign那里)
另外,欢迎到R板来讨论XD
12:50补充: (忘记这种最快的方法)
matplot(cbind(x1,x2), cbind(y1, y2), type = "l")
※ 引述《FengOrz (啦啦啦)》之铭言:
: [软体程式类别]: R
: [程式问题]: x座标略不同如何画在同张图上
: [软体熟悉度]:新手
: [问题叙述]:
: 有两组档案想放在同张图上,我知道可以用par(new=TRUE),但档案的x座标不全相同
: 像是
: x1=c(-0.0436, -0.0406, -0.0322, -0.0284, -0.0108, -0.0066)
: y1=c(0, 3.409091e-05, 2.250000e-04, 3.545455e-04, 1.154545e-03, 1.393182e-03)
: x2=c(-0.2914, -0.1485, -0.1301, -0.1189, -0.0503, -0.0011)
: y2=c(0, 0.001623864, 0.002042045, 0.002423864, 0.002537500, 0.002634091)
: # 如果打
: plot(x1, y1, type = "l")
: par(new=TRUE)
: plot(x2, y2, type = "l", col = "blue")
: 就会看到下方x轴混乱..
: 所以想请教大家不知有无让x轴是正确对到的方法,谢谢!
: [程式范例]:(如上)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.109.73.190
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Statistics/M.1445229379.A.532.html
※ 编辑: celestialgod (140.109.73.190), 10/19/2015 12:52:24
1F:推 FengOrz: 感恩!!谢啦~~~ 10/20 09:58