library(highcharter) library(dplyr) library(viridisLite) library(forecast) library(treemap) library(arules) library(flexdashboard) thm <- hc_theme( colors = c("#1a6ecc", "#434348", "#90ed7d"), chart = list( backgroundColor = "transparent", style = list(fontFamily = "Source Sans Pro") ), xAxis = list( gridLineWidth = 1 ) )
AirPassengers %>% forecast(level = 90) %>% hchart() %>% hc_add_theme(thm)
data("USArrests", package = "datasets") data("usgeojson") USArrests <- USArrests %>% mutate(state = rownames(.)) n <- 4 colstops <- data.frame( q = 0:n/n, c = substring(viridis(n + 1), 0, 7)) %>% list_parse2() highchart() %>% hc_add_series_map(usgeojson, USArrests, name = "Sales", value = "Murder", joinBy = c("woename", "state"), dataLabels = list(enabled = TRUE, format = '{point.properties.postalcode}')) %>% hc_colorAxis(stops = colstops) %>% hc_legend(valueDecimals = 0, valueSuffix = "%") %>% hc_mapNavigation(enabled = TRUE) %>% hc_add_theme(thm)
data("Groceries", package = "arules") dfitems <- tbl_df(Groceries@itemInfo) set.seed(10) dfitemsg <- dfitems %>% mutate(category = gsub(" ", "-", level1), subcategory = gsub(" ", "-", level2)) %>% group_by(category, subcategory) %>% summarise(sales = n() ^ 3 ) %>% ungroup() %>% sample_n(31) tm <- treemap(dfitemsg, index = c("category", "subcategory"), vSize = "sales", vColor = "sales", type = "value", palette = rev(viridis(6))) hctreemap(tm, allowDrillToNode = TRUE, layoutAlgorithm = "squarified") %>% hc_add_theme(thm)
set.seed(2) nprods <- 10 dfitems %>% sample_n(nprods) %>% .$labels %>% rep(times = sort(sample( 1e4:2e4, size = nprods), decreasing = TRUE)) %>% factor(levels = unique(.)) %>% hchart(showInLegend = FALSE, name = "Sales", pointWidth = 10) %>% hc_add_theme(thm) %>% hc_chart(type = "bar")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.