【发布时间】:2020-12-18 19:38:33
【问题描述】:
我正在尝试用指标绘制股票价格,但是我不知道如何在图中添加标签。我想我无法理解 ggplot 如何处理时间序列。我已经看到其他人使用所有数据创建新列,但我不知道这将如何应用在这里。我最初想绘制收盘价以及 50 天和 200 天移动平均线,以及相应的标签。
这里是没有标签的数据和绘图。也欢迎任何有关了解 ggplot 的资源。
structure(c(3.320236, 3.300589, 3.483955, 3.588736, 3.418468,
3.497053, 3.549443, 3.582187, 3.601834, 3.588736, 1803600, 2480600,
2608100, 2315800, 3706400, 2648200, 1851400, 1297000, 2230600,
1667900, 4.04544857999999, 4.01964633999999, 4.00091679999999,
3.98559263999999, 3.96987555999999, 3.95442041999999, 3.94407331999999,
3.93791745999999, 3.92586769999999, 3.91892597999999, 4.80337260999993,
4.79541582999993, 4.78650947499993, 4.77812702499993, 4.76981006499993,
4.76195151999993, 4.75271772499993, 4.74482643499993, 4.73775374499993,
4.72956775999993, 169569500, 167088900, 169697000, 172012800,
168306400, 170954600, 172806000, 174103000, 176333600, 174665700,
3.32023599999963, 3.30058899999973, 3.48395499999974, 3.58873599999971,
3.41846799999982, 3.49705299999975, 3.54944299999964, 3.58218699999948,
3.6018339999997, 3.5887359999996), class = c("xts", "zoo"), index = structure(c(1546387200,
1546473600, 1546560000, 1546819200, 1546905600, 1546992000, 1547078400,
1547164800, 1547424000, 1547510400), tzone = "UTC", tclass = "Date"), .Dim = c(10L,
6L), .Dimnames = list(NULL, c("SPWR.Close", "SPWR.Volume", "SMA",
"SMA.1", "obv", "VWAP")))
ggplot(data = df, aes(x = Date, y = Price)) +
geom_line(aes(y = SPWR.Close)) +
geom_line(aes(y = SMA), col = "red") +
geom_line(aes(y = SMA.1), col = "blue")
【问题讨论】:
-
请正确添加
dput(yourdata),包含的有错别字! -
实际上实现了一个不错的时间序列方法,试试
plot(df)(必须加载library(xts))。
标签: r ggplot2 charts time-series stock