man-roxygen/ex-clust-norun.R

\dontrun{
library(dplyr)

# scale the monthly median close price so that we are clustering on general shape
d <- nasd16 %>%
  group_by(symbol) %>%
  mutate(close_scl = as.numeric(scale(med_close))) %>%
  select(-company, -med_close) %>%
  ungroup()

set.seed(1234)
# k-means clustering with 2, 5, and 9 clusters
km <- get_kmeans(d, x = "month", y = "close_scl", k = c(2, 5, 9, 25))
plot_scree(km)
plot_heat(km, 9, col = "sector")
plot_heat(km, 9, col = "sector", interactive = FALSE,
  display_numbers = TRUE, cutree_cols = 3, cutree_rows = 3)
plot_heat(km, 9, col = "industry", cutoff = 20)

heat <- plot_heat(km, 9, col = "sector", interactive = FALSE,
  display_numbers = TRUE, cutree_cols = 3, cutree_rows = 3,
  annotation_labs = c("A", "B", "C"))
heat

cents <- get_centroid_data(km, 9)
plot_centroid_groups(cents, heat)
}
hafen/seriesclust documentation built on May 17, 2019, 2:24 p.m.