我正在尝试使用" line"来绘制时间序列数据。类型。但它没有正确出来。我有13个变量在一个图表中绘制,具有不同的y轴范围和x轴的datetime
。
> head(eg)
datetime x1 x2 x3 x4 x5 x6
24 2017-06-14 12:00:00 8446.755 7648.031 1111.6707 0.9045327 414.2691 11.778449
25 2017-06-14 13:00:00 6295.053 5660.273 882.6834 0.7028812 415.9553 8.754347
26 2017-06-14 14:00:00 6086.147 5498.443 833.2998 0.6438458 416.5267 8.459638
27 2017-06-14 15:00:00 1850.083 1644.708 254.0441 0.2337391 416.7503 2.569269
28 2017-06-14 16:00:00 5267.201 4773.258 768.3997 0.5249667 416.4483 7.320368
29 2017-06-14 17:00:00 5907.030 5302.488 752.4784 0.6931478 409.5094 8.348385
x7 x8 x9 x10 x11 x12 x13
24 50.00656 57990800 51.76610 1169.014 0.4784138 0.5478276 1.193828
25 50.01681 57994800 51.92203 1199.004 0.4809830 0.6833898 1.174119
26 49.99918 57999183 53.23167 1194.763 0.4223333 0.6339667 1.166983
27 50.01026 58003118 53.97018 1068.251 0.3476316 0.2754211 1.260561
28 50.00910 58007020 49.94800 1188.888 0.4477200 0.5084000 1.171740
29 50.15805 58011111 46.86375 1144.759 0.3844375 0.5530125 1.131637
当我将单个变量映射到x轴时,它就像这样
plot(eg$x1, x = eg$datetime, type = "l")
我可以知道为什么它没有显示直线曲线吗?
感谢。
答案 0 :(得分:0)
列lubridate
的类型是什么?我认为这是一个因素或字符串。 R不会使用分类x轴绘制线条。您可以使用datetime
将df <- data.frame(datetime= c("2017-06-14 12:00:00", "2017-06-14 13:00:00",
"2017-06-14 14:00:00", "2017-06-14 15:00:00", "2017-06-14 16:00:00",
"2017-06-14 17:00:00"), x1 = c(8446.755, 6295.053, 6086.147, 1850.083,
5267.201, 5907.030))
library(lubridate)
plot (df$datetime, df$x1, type="l") # does not work
df$date <- ymd_hms(df$datetime)
plot (df$date, df$x1, type="l") # works
值转换为更好地绘制的内容:
<a href="www.google.com/search?q="how+to+escape+quotes+in+href""</a>