R for
Authoring!!

OOH Session #42…
dygraphs (plus a little threejs)

Open Office Hours
(September 10, 2024)

  • Recap session #41       ↔︎️
  • Focal issue(s):
  • Shared problem-solving

Recap of Session #41:

threejs

THREE = {
  const THREE = window.THREE = await require("three@0.130.0/build/three.min.js");
  await require("three@0.130.0/examples/js/controls/OrbitControls.js").catch(() => {});
  return THREE;
}

height = 350
width = 350

cube = {
  const material = new THREE.MeshNormalMaterial();
  const geometry = new THREE.BoxGeometry(1, 1, 1);
  const cube = new THREE.Mesh(geometry, material);
  return cube;
}

scene = {
  const scene = new THREE.Scene();
  scene.background = new THREE.Color(0x001b42);
  scene.add(cube);
  return scene;
}

camera = {
  const fov = 45;
  const aspect = width / height;
  const near = 1;
  const far = 1000;
  const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
  camera.position.set(2, 2, -2)
  camera.lookAt(new THREE.Vector3(0, 0, 0));
  return camera;
}

renderer = {
  const renderer = new THREE.WebGLRenderer({antialias: true});
  renderer.setSize(width, height);
  renderer.setPixelRatio(devicePixelRatio);
  const controls = new THREE.OrbitControls(camera, renderer.domElement);
  controls.addEventListener("change", () => renderer.render(scene, camera));
  invalidation.then(() => (controls.dispose(), renderer.dispose()));
  return renderer;
}

// Continuously updates
{
  while (true) {
    cube.rotation.z += 0.03;
    cube.rotation.y += 0.03;
    cube.rotation.x += 0.03;
    renderer.render(scene, camera);
    yield null;
  }
}
renderer.domElement
## Actually "social network"
## facebook from Stanford SNAP

library(threejs)
data(ego)
graphjs(ego, bg="black")
## Actually flight patterns

library(threejs)

# Approximate locations as factors
data(flights)

f <- flights

dest   <- factor(sprintf("%.2f:%.2f", f[,3], f[,4]))

# A table of destination frequencies
freq <- sort(table(dest), decreasing=TRUE)

# The most frequent destinations in these data
frequent_destinations <- names(freq)[1:10]

# Subset the flight data by destination frequency
idx <- dest %in% frequent_destinations
frequent_flights <- f[idx, ]

# Lat/long and counts of frequent flights
ll <- unique(frequent_flights[, 3:4])

# Plot frequent destinations as bars, and the flights to and from
# them as arcs. Adjust arc width and color by frequency.
globejs(lat=ll[, 1], long=ll[, 2], arcs=frequent_flights,
        bodycolor="#aaaaff", arcsHeight=0.3, arcsLwd=2,
        arcsColor="#ffff00", arcsOpacity=0.15,
        atmosphere=TRUE, color="#00aaff", pointsize=0.5)

:::

Today:

dygraphs Interactivity

plotly
leaflet
threejs
dygraphs

Session Info (September 10, 2024) Rendering:

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] leaflet_2.1.2     rjson_0.2.21      plotly_4.10.4     ggplot2_3.5.1    
[5] dygraphs_1.1.1.6  threejs_0.3.3     igraph_1.4.2      fontawesome_0.5.2

loaded via a namespace (and not attached):
 [1] zoo_1.8-12        tidyselect_1.2.1  xfun_0.42         purrr_1.0.1      
 [5] lattice_0.20-45   colorspace_2.1-0  vctrs_0.6.5       generics_0.1.3   
 [9] htmltools_0.5.7   viridisLite_0.4.2 emo_0.0.0.9000    yaml_2.3.8       
[13] base64enc_0.1-3   utf8_1.2.4        rlang_1.1.3       pillar_1.9.0     
[17] glue_1.6.2        withr_3.0.0       lifecycle_1.0.4   stringr_1.5.1    
[21] munsell_0.5.1     gtable_0.3.5      htmlwidgets_1.6.4 evaluate_0.23    
[25] knitr_1.45        fastmap_1.1.1     crosstalk_1.2.0   fansi_1.0.6      
[29] xts_0.14.0        scales_1.3.0      jsonlite_1.8.8    farver_2.1.1     
[33] digest_0.6.31     stringi_1.7.12    dplyr_1.1.4       grid_4.2.2       
[37] cli_3.6.0         tools_4.2.2       magrittr_2.0.3    lazyeval_0.2.2   
[41] tibble_3.2.1      crayon_1.5.2      tidyr_1.3.1       pkgconfig_2.0.3  
[45] ellipsis_0.3.2    data.table_1.15.2 timechange_0.3.0  lubridate_1.9.3  
[49] assertthat_0.2.1  rmarkdown_2.26    httr_1.4.7        rstudioapi_0.15.0
[53] R6_2.5.1          compiler_4.2.2