我想绘制一个线图,用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