我想繪製一個線圖,用x軸時間(hh:mm)(這是一個特定的時間間隔), 和y軸平均價格。ggplot:在多個日期上繪製時間圖
我想要圖形顯示多行(每天一行)。
目前我的數據幀是這樣的(我有一些其他變量,以及,但我沒有在我的圖形使用它們相關的有如下):
AV.PRICE DATE TIME
180 2014-01-20 13H 0M 0S
179 2014-01-20 13H 1M 0S
175 2014-01-20 13H 2M 0S
179 2014-01-20 13H 3M 0S
...等等,日期繼續,但時間只需要在價值觀13:00至15:00,每天
Date類是日期間,AV.PRICE是NUM,時間就是如果我的提問階段(使用lubridate)
沒有明確,這就是我正在尋找的,在時間o上繪製日期不可知論圖NLY軸,但我使用GGPLOT2在R:plotting data for different days on a single HH:MM:SS axis
編輯:
當我嘗試繪圖原來的DF與ggplot,它不承認時間變量。 ggplot(df, aes(x=TIME, y=AV.PRICE, group = DATE)) + geom_line()
給error: cannot compare Period to Duration
dput
structure(list(AV.PRICE = c(178.841368677043, 178.837478586724,
178.811640304183, 178.8395125, 178.858236768802, 178.860812464589
), DATE = structure(c(16098, 16098, 16098, 16098, 16098, 16098
), class = "Date"), TIME = structure(c(0, 0, 0, 0, 0, 0), year = c(0,
0, 0, 0, 0, 0), month = c(0, 0, 0, 0, 0, 0), day = c(0, 0, 0,
0, 0, 0), hour = c(13, 13, 13, 13, 13, 13), minute = c(0, 1,
2, 3, 4, 5), class = structure("Period", package = "lubridate"))), .Names = c("AV.PRICE",
"DATE", "TIME"), row.names = c(NA, 6L), class = "data.frame")
它看起來像你的數據已經是長格式的,你想用'melt'做什麼? – Nate
當我嘗試用ggplot繪製原始df時,它不能識別時間變量。 ggplot(df,aes(x = TIME,y = AV.PRICE,group = DATE))+ geom_line()會給出錯誤:無法比較期間與持續時間: – shoestringfries
也許你可以在你的問題中發佈dput(df)看看有沒有人可以幫助你。 – Psidom