英文:
How to ggplot an xts time series in r?
问题
The call to plot() below works, while the call to ggplot() does not. I have very poor vision, perhaps I am missing something obvious?
library(ggplot2)
n=1000
data <- rnorm(n) #Error in rpois(n) : argument "lambda" is missing, with no default
dates <- seq(as.Date("2017-05-01"),length=n,by= "days")
ts <- xts(x=data, order.by=dates)
plot(ts)
ggplot(ts)
英文:
The call to plot() below works, while the call to ggplot() does not. I have very poor vision, perhaps I am missing something obvious?
library(ggplot2)
n=1000
data <- rnorm(n) #Error in rpois(n) : argument "lambda" is missing, with no default
dates <- seq(as.Date("2017-05-01"),length=n,by= "days")
ts <- xts(x=data, order.by=dates)
plot(ts)
ggplot(ts)
答案1
得分: 0
以下是翻译好的部分:
我们可以这样做:
library(ggplot2)
library(xts)
n <- 1000
data <- rnorm(n)
dates <- seq(as.Date("2017-05-01"), length = n, by = "days")
ts <- xts(x = data, order.by = dates)
# 选项1:
autoplot(ts)
# 选项2,使用ggplot2:
ggplot(df, aes(x = Index, y = data)) +
geom_line() +
labs(x = "Date", y = "Value")
英文:
We could do it this way:
library(ggplot2)
library(xts)
n <- 1000
data <- rnorm(n)
dates <- seq(as.Date("2017-05-01"), length = n, by = "days")
ts <- xts(x = data, order.by = dates)
# Option1:
autoplot(ts)
# Option2 using ggplot2
ggplot(df, aes(x = Index, y = data)) +
geom_line() +
labs(x = "Date", y = "Value")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论