The svgPanZoom htmlwidget featured in WEEK 02 | PAN & ZOOM R PLOTS claims that it easily adds pan and zoom interactivity to nearly all R graphs. Here we try out svgPanZoom on a couple of finance charts.
Live Examples
Code to reproduce code.r
| library(DiagrammeR) | |
| mat <- structure( | |
| c(0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, | |
| 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, | |
| 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, | |
| 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, | |
| 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, | |
| 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, |
| library(mgcv) | |
| library(ggplot2) | |
| library(dplyr) | |
| library(XML) | |
| library(weatherData) | |
| us.airports.url <- 'http://www.world-airport-codes.com/us-top-40-airports.html' | |
| us.airports <- readHTMLTable(us.airports.url)[[1]] %>% | |
| filter(!is.na(IATA)) %>% |
The svgPanZoom htmlwidget featured in WEEK 02 | PAN & ZOOM R PLOTS claims that it easily adds pan and zoom interactivity to nearly all R graphs. Here we try out svgPanZoom on a couple of finance charts.
Live Examples
Code to reproduce code.r
| #devtools::install("jeroenooms/V8") | |
| library("V8") | |
| library(pipeR) | |
| ct = new_context("window") | |
| # min.js gives me a call stack size error but non-min works fine | |
| ct$source( | |
| "https://raw.githubusercontent.com/morganherlocker/turf/master/turf.js" | |
| ) | |
| # one of the examples from turf API docs |
| library(V8) | |
| stopifnot(packageVersion("V8") >= "0.5") | |
| # Create V8 context and load viz.js | |
| ct <- new_context("window") | |
| invisible(ct$source('http://mdaines.github.io/viz.js/viz.js')) | |
| # This runs: Viz("digraph { a -> b; }", "svg") | |
| svg <- ct$call("Viz", "digraph { a -> b; }", "svg") | |
| cat(svg) |
| # run these hpdf.js examples | |
| # http://manuels.github.io/hpdf.js/ | |
| # in R with V8 | |
| library(V8) | |
| library(pipeR) | |
| library(htmltools) | |
| ct = new_context("window") | |
| ct$source("https://raw.githubusercontent.com/manuels/hpdf.js/master/hpdf.min.js") |
| category | value | sector | |
|---|---|---|---|
| UK production emissions | 632 | UK | |
| Carbon flows from EU | 88 | EU | |
| Carbon flows to EU | -61 | EU | |
| Carbon flows from other Annex 1 | 82 | Annex 1 | |
| Carbon flows to other Annex 1 | -39 | Annex 1 | |
| Carbon flows from non-Annex 1 | 104 | Other non-Annex 1 | |
| Carbon flows from non-Annex 1 | 64 | China | |
| Carbon flows to non-Annex 1 | -25 | Non-Annex 1 | |
| UK consumption emissions | 845 | UK |
| # Reading in 'dogs.csv' | |
| # Created by Alex Bresler, available at: | |
| # https://github.com/abresler/abresler.github.io/blob/master/blog/2015/february/exploring_agility_show/data/dogs.csv | |
| dogs <- read.csv("dogs.csv", header = TRUE, stringsAsFactors = FALSE) | |
| # Setting a numeric id | |
| node_id <- 1:nrow(dogs) | |
| # Getting unique values for the 'breed' column | |
| unique_node_2 <- unique(dogs$breed) |
| library(V8) | |
| # Create function to generate palette of visually different colors | |
| hex_palette <- function(no_colors, | |
| hue_range = NULL, | |
| chroma_range = NULL, | |
| lightness_range = NULL){ | |
| pal <- function(col, border = "light gray", ...){ | |
| n <- length(col) |