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