time_ggplot | R Documentation |
time_ggplot()
is a neat way to quickly
plot aggregate time-series data.
time_ggplot(
data,
time,
value,
group = NULL,
facet = FALSE,
geom = ggplot2::geom_line,
...
)
data |
A data frame |
time |
Time variable using |
value |
Value variable using |
group |
(Optional) Group variable using |
facet |
When groups are supplied, should multi-series be
plotted separately or on the same plot?
Default is |
geom |
|
... |
Further arguments passed to the chosen 'geom'. |
A ggplot
.
ts_as_tbl
library(dplyr)
library(timeplyr)
library(ggplot2)
library(lubridate)
# It's as easy as this
AirPassengers %>%
ts_as_tbl() %>%
time_ggplot(time, value)
# And this
EuStockMarkets %>%
ts_as_tbl() %>%
time_ggplot(time, value, group)
# Converting this to monthly averages
EuStockMarkets %>%
ts_as_tbl() %>%
mutate(month = year_month_decimal(time)) %>%
summarise(avg = mean(value),
.by = c(group, month)) %>%
time_ggplot(month, avg, group)
# zoo example
x.Date <- as.Date("2003-02-01") + c(1, 3, 7, 9, 14) - 1
x <- zoo::zoo(rnorm(5), x.Date)
x %>%
ts_as_tbl() %>%
time_ggplot(time, value)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.