1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/globe.R
\name{globejs}
\alias{globejs}
\title{Plot Data on 3D Globes}
\usage{
globejs(
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,
elementId = NULL,
...
)
}
\arguments{
\item{img}{A character string representing a file path or URI of an image to plot on the globe surface.}
\item{lat}{Optional data point decimal latitudes, must be of same length as \code{long}
(negative values indicate south, positive north).}
\item{long}{Optional data point decimal longitudes, must be of same length as \code{lat}
(negative values indicate west, positive east).}
\item{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.}
\item{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.}
\item{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.}
\item{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}.}
\item{arcsHeight}{A single value between 0 and 1 controlling the height above the globe of each arc.}
\item{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}.}
\item{arcsOpacity}{A single value between 0 and 1 indicating the opacity of all arcs.}
\item{atmosphere}{TRUE enables WebGL atmpsphere effect.}
\item{bg}{Plot background color.}
\item{height}{The container div height.}
\item{width}{The container div width.}
\item{elementId}{Use an explicit element ID for the widget (rather than an automatically generated one). Useful if you have other JavaScript that needs to explicitly discover and interact with a specific widget instance.}
\item{...}{Additional arguments to pass to the three.js renderer (see
below for more information on these options).}
}
\value{
An htmlwidget object (displayed using the object's show or print method).
}
\description{
Plot points, arcs and images on a globe in 3D using Three.js. The globe
can be rotated and and zoomed.
}
\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 = "#000000"}, and \code{bodycolor = "#ffffff"}.
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.
}
\examples{
# 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,
bodycolor="#aaaaff", arcsHeight=0.3, arcsLwd=2,
arcsColor="#ffff00", arcsOpacity=0.15,
atmosphere=TRUE, color="#00aaff", pointsize=0.5)
\dontrun{
# 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)
col <- colorRampPalette(c("cyan", "lightgreen"))(10)[floor(10 * 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", lightcolor="#aaaaaa",
lat=cities$lat, long=cities$long,
value=value, color=col)
# Using global plots from the maptools, rworldmap, or sp packages.
# Instead of using ready-made images of the earth, we can use
# many 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,
setParUsrBB=TRUE)
dev.off()
globejs(earth)
# A shiny example:
shiny::runApp(system.file("examples/globe",package="threejs"))
}
# See http://bwlewis.github.io/rthreejs for additional examples.
}
\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}
}
|