-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0767500
Showing
38 changed files
with
5,674 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Package: threejs | ||
Type: Package | ||
Title: Interactive 3D Scatter Plots and Globes | ||
Description: Create interactive 3D scatter plots and globes using the 'three.js' visualization library ("http://threejs.org"). | ||
Version: 0.2.1 | ||
Date: 2015-04-24 | ||
Author: B. W. Lewis <blewis@illposed.net> | ||
Maintainer: B. W. Lewis <blewis@illposed.net> | ||
URL: http://bwlewis.github.io/rthreejs | ||
License: MIT + file LICENSE | ||
Depends: R (>= 3.0.0) | ||
Imports: htmlwidgets (>= 0.3.2), base64enc | ||
Suggests: htmltools (>= 0.2.6), RCurl, maps, sp | ||
Enhances: knitr, shiny | ||
NeedsCompilation: no | ||
Packaged: 2015-05-19 02:34:45 UTC; blewis | ||
Repository: CRAN | ||
Date/Publication: 2015-05-19 06:13:04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2015 | ||
COPYRIGHT HOLDER: Bryan W. Lewis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
3fc2c2177d54f2c8d977ec7d5d2f9c3b *DESCRIPTION | ||
3cf7b53d0def2bbc53239b3a2e7c5cb8 *LICENSE | ||
7a2d3dc9d5c4e3bfee6306a95b2289d8 *NAMESPACE | ||
b112b1d367ea76ebff1e2bd4d135bfe4 *R/data-definitions.R | ||
051efe60156661df8c3271b3767a82b4 *R/globe.R | ||
0224fae71ba837e799c934c209c37759 *R/scatterplot.R | ||
a55e502568cb1ed387ce79d03b00f665 *R/threejs.R | ||
7804250ab7c05cdacccdde043639c111 *R/utilities.R | ||
e40283f4b7c0a3c007ce60dc409b34bf *README.md | ||
ed163e2377183a7d094e4135b2e62cd2 *data/flights.RData | ||
c286f1b4c2ca6685df7d0cfc5c685e76 *inst/examples/globe/server.R | ||
f8928b8694b3cce07e12fd93e0152a86 *inst/examples/globe/ui.R | ||
4db710bc97e35fa599c99317d8be06b7 *inst/examples/scatterplot/server.R | ||
2de1ea840f88045bc8e4634ba30b8d3a *inst/examples/scatterplot/ui.R | ||
82995fd3535793e62ada0f258122a8a7 *inst/htmlwidgets/globe.js | ||
2d3f4f4cac7f22cbed7e8b380caf8699 *inst/htmlwidgets/globe.yaml | ||
3255ea1f743500a5460a1edde9995eb7 *inst/htmlwidgets/lib/d3-3.5.4/d3.min.js | ||
305dbc77cc24efe7544cd1dabb34517d *inst/htmlwidgets/lib/threejs-70/CanvasRenderer.js | ||
d8c3876bb8d4f426bdb3a293ae401bb8 *inst/htmlwidgets/lib/threejs-70/Detector.js | ||
8ac4ade53aa3d481066d90d15b1afbaf *inst/htmlwidgets/lib/threejs-70/OrbitControls.js | ||
5abec346a44615221381b3dc693b72bd *inst/htmlwidgets/lib/threejs-70/Projector.js | ||
c9071d7581fba01d27e2e9308c384d17 *inst/htmlwidgets/lib/threejs-70/three.min.js | ||
6bd65d27741b851797852e7724e8d504 *inst/htmlwidgets/scatterplotThree.js | ||
2d3f4f4cac7f22cbed7e8b380caf8699 *inst/htmlwidgets/scatterplotThree.yaml | ||
79b9e9384834cbb8f90dd8833cbeeb26 *inst/images/circle.png | ||
708d01dffedb283c365c8c67aa36c04f *inst/images/disc.png | ||
f68fddf3d9668aa84f8e2b7e71142ee1 *inst/images/jupiter.jpg | ||
3225e0725e910325e465689e0805160e *inst/images/mars.jpg | ||
e03d6618d840119bbf1b6fdbac1f23a1 *inst/images/moon.jpg | ||
41dc495690510741c61bbeda8107c947 *inst/images/plus.png | ||
b3ac7597e5f87cc4e0d39f36e3104656 *inst/images/world.jpg | ||
2065813f8177102c22de47ba395912aa *man/flights.Rd | ||
fac71f82d981433655c2e51699412c04 *man/globejs.Rd | ||
f721e084925a786da8c8234e57134dd0 *man/scatterplot3js.Rd | ||
424095c5fcff1f09e3b35353d5f30870 *man/texture.Rd | ||
ddf5934d669d6e16476d7c7bccf01353 *man/threejs-package.Rd | ||
0bc699581f688105fb6117b662b1f23f *man/threejs-shiny.Rd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Generated by roxygen2 (4.1.1): do not edit by hand | ||
|
||
export(globeOutput) | ||
export(globejs) | ||
export(renderGlobe) | ||
export(renderScatterplotThree) | ||
export(scatterplot3js) | ||
export(scatterplotThreeOutput) | ||
export(texture) | ||
importFrom(base64enc,dataURI) | ||
importFrom(htmlwidgets,shinyRenderWidget) | ||
importFrom(htmlwidgets,shinyWidgetOutput) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
#' Global flight example data from Callum Prentice. | ||
#' | ||
#' @docType data | ||
#' @source See Callum Prentice \url{https://raw.githubusercontent.com/callumprentice/callumprentice.github.io/master/apps/flight_stream/js/flights_one.js} | ||
#' @keywords datasets | ||
#' @format A data frame with 34,296 observations of 4 variables, origin_lat, origin_long, dest_lat, and dest_long. | ||
#' @name flights | ||
#' | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
#' globejs Three.js globe widget | ||
#' | ||
#' Three.js widget for mapping points, arcs and images on a globe. The globe | ||
#' can be rotated and and zoomed. | ||
#' | ||
#' @param img A character string representing a file path or URI of an image to plot on the globe surface. | ||
#' @param lat Optional data point decimal latitudes, must be of same length as \code{long} (negative values indicate south, positive north). | ||
#' @param long Optional data point decimal longitudes, must be of same length as \code{lat} (negative values indicate west, positive east). | ||
#' @param color Either a single color value indicating the color of all data points, or a vector of values of the same length as \code{lat} indicating color of each point. | ||
#' @param value Either a single value indicating the height of all data points, or a vector of values of the same length as \code{lat} indicating height of each point. | ||
#' @param arcs Optional four-column data frame specifying arcs to plot. The columns of the data frame, in order, must indicate the starting latitude, starting longitude, ending latitude, and ending longitude. | ||
#' @param arcsColor Either a single color value indicating the color of all arcs, or a vector of values of the same length as the number of rows of \code{arcs}. | ||
#' @param arcsLwd Either a single value indicating the line width of all arcs, or a vector of values of the same length as the number of rows of \code{arcs}. | ||
#' @param arcsHeight A single value between 0 and 1 controlling the height above the globe of each arc. | ||
#' @param arcsOpacity A single value between 0 and 1 indicating the opacity of all arcs. | ||
#' @param atmosphere TRUE enables WebGL atmpsphere effect. | ||
#' @param bg Plot background color. | ||
#' @param width The container div width. | ||
#' @param height The container div height. | ||
#' @param ... Additional arguments to pass to the three.js renderer (see | ||
#' below for more information on these options). | ||
#' | ||
#' @note | ||
#' The \code{img} argument specifies the WebGL texture image to wrap on a | ||
#' sphere. If you plan to plot points using \code{lat} and \code{lon} | ||
#' the image must be a plate carree (aka lat/long) equirectangular | ||
#' map projection; see | ||
#' \url{https://en.wikipedia.org/wiki/Equirectangular_projection} for | ||
#' details.. | ||
#' Lat/long maps are commonly found for most planetary bodies in the | ||
#' solar system, and are also easily generated directly in R | ||
#' (see the references and examples below). | ||
#' | ||
#' @section Available rendering options: | ||
#' \itemize{ | ||
#' \item{"bodycolor"}{ The diffuse reflective color of the globe.} | ||
#' \item{"emissive"}{ The emissive color of the globe object.} | ||
#' \item{"lightcolor"}{ The color of the ambient light in the scene.} | ||
#' \item{"fov"}{ The initial field of view, default is 35.} | ||
#' \item{"rotationlat"}{ The initial globe latitudinal rotation in radians, default is 0.} | ||
#' \item{"rotationlong"}{ The initial globe longitudinal rotation in radians, default is 0.} | ||
#' \item{"pointsize"}{ The numeric size of the points/bars, default is 1.} | ||
#' \item{"renderer"}{ Manually set the three.js renderer to one of 'auto' or 'canvas'. | ||
#' The canvas renderer works across a greater variety of | ||
#' viewers and browsers. The default setting of 'auto' automatically chooses | ||
#' WebGL rendering if it's available.} | ||
#' } | ||
#' Specify colors with standard color names or hex color representations. | ||
#' The default values (well-suited to many earth-like map images) are | ||
#' \code{lightcolor = "#aaeeff"}, \code{emissive = "#0000ff"}, and \code{bodycolor = "#0000ff"}. | ||
#' Larger \code{fov} values result in a smaller (zoomed out) globe. | ||
#' The latitude and longitude rotation values are relative to the center of | ||
#' the map image. Their default values of zero radians result in the front of the | ||
#' globe corresponding to the center of the flat map image. | ||
#' | ||
#' @references | ||
#' The three.js project \url{http://threejs.org}. | ||
#' (The corresponding three.js javascript file is in | ||
#' \code{ system.file("htmlwidgets/globejs",package="threejs")}.) | ||
#' | ||
#' An excellent overview of available map coordinate reference systems (PDF): | ||
#' \url{https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/OverviewCoordinateReferenceSystems.pdf} | ||
#' | ||
#' Includes ideas and images from the dat.globe Javascript WebGL Globe Toolkit | ||
#' Copyright 2011 Data Arts Team, Google Creative Lab | ||
#' Licensed under the Apache License, Version 2.0 | ||
#' \url{http://www.apache.org/licenses/LICENSE-2.0} | ||
#' | ||
#' NASA Blue Marble/MODIS Earth images \url{visibleearth.nasa.gov} | ||
#' | ||
#' Moon image: \url{http://maps.jpl.nasa.gov/textures/ear1ccc2.jpg}. | ||
#' | ||
#' Mars image: \url{http://pdsmaps.wr.usgs.gov/PDS/public/explorer/html/marsadvc.htm}. | ||
#' | ||
#' Jupiter image: \url{http://maps.jpl.nasa.gov/textures/jup0vtt2.jpg}. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' library("threejs") | ||
#" | ||
#' # Plot flights to frequent destinations from | ||
#' # Callum Prentice's global flight data set, | ||
#' # http://callumprentice.github.io/apps/flight_stream/index.html | ||
#' data(flights) | ||
#' # Approximate locations as factors | ||
#' dest <- factor(sprintf("%.2f:%.2f",flights[,3], flights[,4])) | ||
#' # A table of destination frequencies | ||
#' freq <- sort(table(dest), decreasing=TRUE) | ||
#' # The most frequent destinations in these data, possibly hub airports? | ||
#' frequent_destinations <- names(freq)[1:10] | ||
#' # Subset the flight data by destination frequency | ||
#' idx <- dest %in% frequent_destinations | ||
#' frequent_flights <- flights[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, | ||
#' arcsHeight=0.3, arcsLwd=2, arcsColor="#ffff00", arcsOpacity=0.15, | ||
#' atmosphere=TRUE, color="#00aaff", pointsize=0.5) | ||
#' | ||
#' # A shiny example: | ||
#' | ||
#' shiny::runApp(system.file("examples/globe",package="threejs")) | ||
#' | ||
#' # Plot populous world cities from the 'maps' package. | ||
#' library("threejs") | ||
#' library("maps") | ||
#' data(world.cities, package="maps") | ||
#' cities <- world.cities[order(world.cities$pop,decreasing=TRUE)[1:1000],] | ||
#' value <- 100 * cities$pop / max(cities$pop) | ||
#' | ||
#' # Set up a data color map and plot | ||
#' col <- rainbow(10,start=2.8/6,end=3.4/6) | ||
#' col <- col[floor(length(col)*(100-value)/100) + 1] | ||
#' globejs(lat=cities$lat, long=cities$long, value=value, color=col, atmosphere=TRUE) | ||
#' | ||
#' # Plot the data on the moon: | ||
#' moon <- system.file("images/moon.jpg", package="threejs") | ||
#' globejs(img=moon, bodycolor="#555555", emissive="#444444", | ||
#' lightcolor="#555555", lat=cities$lat, long=cities$long, | ||
#' value=value, color=col) | ||
#' | ||
#' # Plot a high-resolution NASA MODIS globe (it can take a while to download | ||
#' # the image!) | ||
#' globejs(paste("http://eoimages.gsfc.nasa.gov/", | ||
#' "images/imagerecords/73000/73909/", | ||
#' "world.topo.bathy.200412.3x5400x2700.jpg",sep="") | ||
#' | ||
#' # Using global plots from the maptools, rworldmap, or sp packages. | ||
#' | ||
#' # Instead of using ready-made images of the earth, we can employ some | ||
#' # incredibly capable R spatial imaging packages to produce globe images | ||
#' # dynamically. With a little extra effort you can build globes with total | ||
#' # control over how they are plotted. | ||
#' | ||
#' library("maptools") | ||
#' library("threejs") | ||
#' data(wrld_simpl) | ||
#' | ||
#' bgcolor <- "#000025" | ||
#' earth <- tempfile(fileext=".jpg") | ||
#' | ||
#' | ||
#' # NOTE: Use antialiasing to smooth border boundary lines. But! Set the jpeg | ||
#' # background color to the globe background color to avoid a visible aliasing | ||
#' # effect at the the plot edges. | ||
#' | ||
#' jpeg(earth,width=2048,height=1024,quality=100,bg=bgcolor,antialias="default") | ||
#' par(mar = c(0,0,0,0), pin = c(4,2), pty = "m", xaxs = "i", | ||
#' xaxt = "n", xpd = FALSE, yaxs = "i", bty = "n", yaxt = "n") | ||
#' plot(wrld_simpl, col="black", bg=bgcolor, border="cyan", ann=FALSE, | ||
#" axes=FALSE, xpd=FALSE, xlim=c(-180,180), ylim=c(-90,90), | ||
#' setParUsrBB=TRUE) | ||
#' dev.off() | ||
#' globejs(earth) | ||
#' See http://bwlewis.github.io/rthreejs for additional examples. | ||
#' } | ||
#' | ||
#' @export | ||
globejs <- function( | ||
img=system.file("images/world.jpg", package="threejs"), | ||
lat, long, | ||
value=40, | ||
color="#00ffff", | ||
arcs, | ||
arcsColor="#99aaff", | ||
arcsHeight=0.4, | ||
arcsLwd=1, | ||
arcsOpacity=0.2, | ||
atmosphere=FALSE, | ||
bg="black", | ||
height = NULL, | ||
width = NULL, ...) | ||
{ | ||
if(missing(lat)|| missing(long)) | ||
{ | ||
lat = NULL | ||
long = NULL | ||
} | ||
# Strip alpha channel from colors | ||
i = grep("^#",color) | ||
if(length(i)>0) | ||
{ | ||
j = nchar(color[i])>7 | ||
if(any(j)) | ||
{ | ||
color[i][j] = substr(color[i][j],1,7) | ||
} | ||
} | ||
i = grep("^#",arcsColor) | ||
if(length(i)>0) | ||
{ | ||
j = nchar(arcsColor[i])>7 | ||
if(any(j)) | ||
{ | ||
arcsColor[i][j] = substr(arcsColor[i][j],1,7) | ||
} | ||
} | ||
i = grep("^#",bg) | ||
if(length(i)>0) bg = substr(bg,1,7) | ||
if(missing(arcs)) | ||
arcs=NULL | ||
else | ||
{ | ||
arcs = data.frame(arcs) | ||
names(arcs) = c("fromlat","fromlong","tolat","tolong") | ||
} | ||
arcsHeight = max(min(arcsHeight, 1), 0.2) | ||
arcsOpacity = max(min(arcsOpacity,1),0) | ||
|
||
options = list(lat=lat, long=long, color=color, arcsOpacity=arcsOpacity, | ||
value=value, atmosphere=atmosphere, bg=bg, arcs=arcs, | ||
arcsColor=arcsColor, arcsLwd=arcsLwd, arcsHeight=arcsHeight) | ||
additional_args = list(...) | ||
if(length(additional_args)>0) options = c(options, additional_args) | ||
# Clean up optional color arguments | ||
if("bodycolor" %in% names(options)) | ||
{ | ||
i = grep("^#",options$bodycolor) | ||
if(length(i)>0) options$bodycolor = substr(options$bodycolor,1,7) | ||
} | ||
if("emissive" %in% names(options)) | ||
{ | ||
i = grep("^#",options$emissive) | ||
if(length(i)>0) options$emissive = substr(options$emissive,1,7) | ||
} | ||
if("lightcolor" %in% names(options)) | ||
{ | ||
i = grep("^#",options$lightcolor) | ||
if(length(i)>0) options$lightcolor = substr(options$lightcolor,1,7) | ||
} | ||
|
||
# Convert image files to dataURI using the texture function | ||
if(!is.list(img)) img=texture(img) | ||
x = c(img, options) | ||
htmlwidgets::createWidget( | ||
name = "globe", | ||
x = x, | ||
width = width, | ||
height = height, | ||
htmlwidgets::sizingPolicy(padding = 0, browser.fill = TRUE), | ||
package = "threejs") | ||
} | ||
|
||
#' @rdname threejs-shiny | ||
#' @export | ||
globeOutput <- function(outputId, width = "100%", height = "600px") { | ||
shinyWidgetOutput(outputId, "globe", width, height, | ||
package = "threejs") | ||
} | ||
|
||
#' @rdname threejs-shiny | ||
#' @export | ||
renderGlobe <- function(expr, env = parent.frame(), quoted = FALSE) { | ||
if (!quoted) { expr <- substitute(expr) } # force quoted | ||
shinyRenderWidget(expr, globeOutput, env, quoted = TRUE) | ||
} |
Oops, something went wrong.