Re: [问题] 关于多条折线图的方式

楼主: cty78221 (囧)   2021-10-10 10:36:11
※ 引述《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
作者: locka (locka)   2021-10-10 12:25:00
感谢分享,原来 matplot()等价于 plot( …, add=TRUE) 这样就不用一条一条加了

Links booklink

Contact Us: admin [ a t ] ucptt.com