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:
You will need a nominal variable that represents a geographic area and a numeric variable in your Data Sets tree.
A nominal variable is represented by two circles next to its name:
Numeric variables are represented by a "2" next to their name:
- Import the data by going to the toolbar, and selecting Anything > Data > Data Set > Add. In this example, I am loading in data from a URL: https://wiki.q-researchsoftware.com/images/e/e2/WUP2018-F13-Capital_Cities.xls. You can ignore the warning about multiple sheets. Rename the imported data set "CapitalCities".
- Ensure that you have a numeric variable available in your data set. In this example, the Population (thousands) variable is imported as text (which you can tell by the letter "a" before the variable name). To convert it to a number, click on it then from the object inspector under Properties on the right of the screen change Structure to Numeric. This creates a new numeric variable in the Data Set called "Population (thousands)1".
- From the toolbar, go to Calculation > Custom Code.
- Paste the following code in the object inspector > Properties > R CODE and click Calculate:
# Make a data.frame of the required information
x <- data.frame(long = Longitude,
lat = Latitude,
population = `Population (thousands)1`,
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")