This article describes how to go from summarized global geographic data, such as the population of capital cities around the world:
To a state where the summarized data is captured in an interactive globe visualization:
Requirements
You will need a nominal variable that represents a geographic area and a numeric variable in your Data Sources tree.
A nominal variable is represented by two circles next to its name:
Numeric variables are represented by a "2" next to their name:
Method
- Upload the file by clicking Add Data and selecting the appropriate method (see How to Import Data Into Displayr for more information. In this example, I am loading in data from a URL: https://wiki.q-researchsoftware.com/images/e/e2/WUP2018-F13-Capital_Cities.xls.
- Ensure that a numeric variable is available in your data set. In this example, the Population (thousands) variable is imported as numeric (you can tell by the number "2" before the variable name).
- From the toolbar, go to Calculation
> Custom Code.
- Paste the following code in the R Code editor and click Calculate:
library(threejs)
library(flipChartBasics)
# Make a data.frame of the required information
x <- data.frame(long = Longitude,
lat = Latitude,
population = `Population (thousands)`,
city = `Capital City`)
# Set colors according to first letter of city name
first.letters <- sapply(substring(x$city, 1, 1),
utf8ToInt) - utf8ToInt("A") + 1
palette <- ChartColors(26, "Blues")
colors <- palette[first.letters]
# Plot the data on the globe
earth <- "http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73909/world.topo.bathy.200412.3x5400x2700.jpg"
globejs(img = earth,
lat = x$lat,
long = x$long,
val = 10 * log(x$population),
color = colors,
pointsize = 5,
atmosphere = FALSE,
bg = "white")
UPCOMING WEBINAR: 10 Market Research Predictions Over the Next 4 Years