看板 R_Language 關於我們 聯絡資訊
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 請把以下不需要的部份刪除 入門(寫過其他程式,只是對語法不熟悉) [問題敘述]: 請簡略描述你所要做的事情,或是這個程式的目的 我有三組在三個時間點所測量的資料,我想要把三組的資料用不同的顏色畫成折線圖 畫在同一個圖上,目前我的方法是先用plot畫第一組的資料,然後再用 points把另外兩組的加上去,想要問有沒有其他的畫法? [程式範例]: data <- data.frame('group' = rep(1:3,each = 3), 'time' = rep(1:3,3), 'IV' = rnorm(9, 10, 4)) with(subset(data, group == '1'), plot(time, IV, type = 'b', col = 1, ylim = c(0,50))) with(subset(data, group == '2'), points(time, IV, type = 'b', col = 2, add = T)) with(subset(data, group == '3'), points(time, IV, type = 'b', col = 3, add = T)) legend('topright', pch = 1,col = 1:3, legend = c('group1', 'group2', 'group3')) [環境敘述]: R3.2 [關鍵字]: plot -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.248.64.34 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1432992612.A.199.html
celestialgod: ?matplot 05/31 00:25
celestialgod: 或是library(lattice), xyplot(IV~time, groups=gro 05/31 00:26
celestialgod: up) 05/31 00:26
celestialgod: ggplot2也可以,ggplot(data, aes(x=time, y=IV, gr 05/31 00:29
celestialgod: oup=group)) + geom_line() 05/31 00:29
DrRd: 感謝提供!我來試試ggplot2! 05/31 11:33
andrew43: 說真的,內建的「傳統」畫法就是原po的方法沒錯。 05/31 22:46
celestialgod: matplot也是內建的畫法XD 05/31 22:53