# NOT RUN {
# lynx is a time.series object
lynx_num.df <-
try_tibble(lynx,
col.names = c("year", "lynx"),
as.numeric = TRUE) # years -> as numeric
ggplot(lynx_num.df, aes(year, lynx)) +
geom_line() +
stat_peaks(colour = "red") +
stat_valleys(colour = "blue")
ggplot(lynx_num.df, aes(year, lynx)) +
geom_line() +
stat_peaks(colour = "red") +
stat_peaks(colour = "red", geom = "rug")
ggplot(lynx_num.df, aes(year, lynx)) +
geom_line() +
stat_peaks(colour = "red") +
stat_peaks(colour = "red", geom = "text", hjust = -0.1, angle = 33)
lynx_datetime.df <-
try_tibble(lynx,
col.names = c("year", "lynx")) # years -> POSIXct
ggplot(lynx_datetime.df, aes(year, lynx)) +
geom_line() +
stat_peaks(colour = "red") +
stat_valleys(colour = "blue")
ggplot(lynx_datetime.df, aes(year, lynx)) +
geom_line() +
stat_peaks(colour = "red") +
stat_peaks(colour = "red",
geom = "text",
hjust = -0.1,
x.label.fmt = "%Y",
angle = 33)
# }
Run the code above in your browser using DataLab