作者cty78221 (囧)
看板R_Language
标题Re: [问题] 关於多条折线图的方式
时间Sun Oct 10 10:36:11 2021
※ 引述《lin810221 (LiNz)》之铭言:
: 假设我有两组资料
: 左边为水位高度(Y轴);右边为时间(X轴)
: https://imgur.com/a/4PCzgEK
: 我的程式写法:
: x1 = c(3.5, 4.5, 5.7, 7.9)
: y1 = c(1.3, 1.35, 1.41, 1.56)
: plot(x1, y1, type = "l", ylim = c(0, 2)) #这边没设定Y轴好像没办法画多条图?
: x2 = c(3.2, 4.5, 5.7, 7.9)
: y2 = c(1.2, 1.21, 1.25, 1.5)
: lines(x2, y2)
: 可是我有很多条要画,有想过建立两个datafram然後用for回圈去跑,
: 不过我数据太大时,每次跑一次程式都要等一段时间,
: 所以想问版上大大有无其他函式可以让我直接把两组dataframe的资料一次画出多条折线图
matplot(cbind(x1, x2), cbind(y1,y2), type = "l")
参考出处:
https://stackoverflow.com/questions/2564258/plot-two-graphs-in-same-plot-in-r
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.122.208.49 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1633833374.A.CC6.html
1F:推 locka: 感谢分享,原来 matplot()等价於 plot( …, add=TRUE) 这样 10/10 12:25
2F:推 locka: 就不用一条一条加了 10/10 12:25