d3r
aims to make d3.js
easy in R. Here is an example of combining d3.quadtree
with base graphics in R using the new d3_v8()
function.
# d3.quadtree example
library(d3r)
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>3dep-tile-client</title> | |
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"> | |
<link href="https://api.mapbox.com/mapbox-gl-js/v2.11.0/mapbox-gl.css" rel="stylesheet"> | |
<script src="https://api.mapbox.com/mapbox-gl-js/v2.11.0/mapbox-gl.js"></script> | |
<style> |
#' Smooths a 2D field | |
#' | |
#' @param x,y Vector of x and y coordinates | |
#' @param value Vector of values | |
#' @param kx,ky Proportion of components to keep in the x and | |
#' y direction respectively. Lower values increased the smoothness. | |
#' | |
#' @examples | |
#' library(ggplot2) | |
#' # Creates a noisy version of the volcano dataset and applies the smooth |
#anglr questions | |
# example... | |
library(gdalio) | |
library(rayshader) | |
library(topography) | |
library(gdalwebsrv) | |
library(anglr) | |
source(system.file("raster_format/raster_format.codeR", package = "gdalio", mustWork = TRUE)) | |
#functions... |
MIT Licensed. Copyright (c) 2021 [email protected] | |
Share and Enjoy. | |
## Introduction | |
This code was a personal challenge to write a simple ray-tracer in pure R. | |
Ray tracing is an example of something which is really silly to do in base R, | |
and I'd be interested to see how others would approach this problem. |
library(rgl) | |
sl <- shapelist3d(cube3d(alpha = 1, | |
color = 'grey90', | |
specular = 'black', | |
lit = TRUE), | |
plot = FALSE) | |
create_next_level <- function(sl, level) { | |
library(rgl) | |
pan3d <- function(button, dev = rgl.cur(), subscene = currentSubscene3d(dev)) { | |
start <- list() | |
begin <- function(x, y) { | |
activeSubscene <- par3d("activeSubscene", dev = dev) | |
start$listeners <<- par3d("listeners", dev = dev, subscene = activeSubscene) | |
for (sub in start$listeners) { |
#include <Rcpp.h> | |
using namespace Rcpp; | |
// turmite function to be called from R | |
// [[Rcpp::export]] | |
NumericMatrix flame(int iter, int layers) { | |
NumericMatrix points(iter, 3); // initially zero | |
NumericMatrix coeffs(9, layers); | |
mk_name <- function(name=NULL) { | |
v <- as.character(packageVersion('rayrender')) | |
dir <- file.path('~', 'Downloads', 'rr-tests') | |
if(is.null(name)) { | |
name <- sprintf( 'a_%s.png', format(Sys.time(), "%Y-%m-%d_%H%M%S")) | |
} else { | |
name <- sprintf('%s.png', name) | |
} | |
file.path(dir, v, name) | |
} |
############################################ | |
### Extract NSIDC geotiff data to points ### | |
############################################ | |
#Many thanks to mdsumner for help with this: | |
#https://github.com/mdsumner/extractNSIDC/blob/master/extract_script.R | |
#Load libraries | |
require(tidyverse) | |
require(lubridate) |
d3r
aims to make d3.js
easy in R. Here is an example of combining d3.quadtree
with base graphics in R using the new d3_v8()
function.
# d3.quadtree example
library(d3r)