【发布时间】:2015-10-22 14:29:45
【问题描述】:
我希望能够使用黄土 (STL) 和 Ggvis 绘制季节性趋势分解的三个不同元素。
但是,我收到此错误:
Error: data_frames can only contain 1d atomic vectors and lists
我正在使用 nottem 数据集。
# The Seasonal Trend Decomposition using Loess (STL) with Ggvis
# Load nottem data set
library(datasets)
nottem <- nottem
# Decompose using stl()
nottem.stl = stl(nottem, s.window="periodic")
# Plot decomposition
plot(nottem.stl)
现在,这是我感兴趣的信息。为了把它变成一个我可以玩的情节,我使用 xts-package 将它转换成一个数据框。到目前为止一切顺利。
# Transform nottem.stl to a data.frame
library(xts)
df.nottem.stl <- as.data.frame(as.xts(nottem.stl$time.series))
# Add date to data.frame
df.nottem.stl$date <- data.frame(time = seq(as.Date("1920-01-01"), by = ("months"), length =240))
# Glimpse data
glimpse(df.nottem.stl)
# Plot simple line of trend
plot(df.nottem.stl$date, df.nottem.stl$trend, type = "o")
这几乎是我想要的情节。但是,我希望能够将它与 Shiny 一起使用,因此 Ggvis 更可取。
# Plot ggvis
df.nottem.stl%>%
ggvis(~date, ~trend)%>%
layer_lines()
这是我得到错误的地方。
关于可能出错的任何提示?
【问题讨论】: