rworldmap is a relatively new package available on CRAN for the mapping and visualisation of global data. The vision is to make the display of global data easier, to facilitate understanding and communication. The initial focus is on data referenced by country or grid due to the frequency of use of such data in global assessments. Tools to link data referenced by country (either name or code) to a map, and then to display the map are provided as are functions to map global gridded data. Country and gridded functions accept the same arguments to specify the nature of categories and colour and how legends are formatted. This package builds on the functionality of existing packages, particularly sp, maptools and fields. Example code is provided to produce maps, to link with the packages classInt, RColorBrewer and ncdf, and to plot examples of publicly available country and gridded data.
Global datasets are becoming increasingly common and are frequently seen on the web, in journal papers and in our newspapers (for example a ‘carbon atlas’ of global emissions available at http://image.guardian.co.uk/sys-files/Guardian/documents/2007/12/17/CARBON_ATLAS.pdf). At the same time there is a greater interest in global issues such as climate change, the global economy, and poverty (as for example outlined in the Millenium Development Goals, http://www.un.org/millenniumgoals/bkgd.shtml). Thirdly, there is an increasing availability of software tools for visualising data in new and interesting ways. Gapminder (http://www.gapminder.org) has pioneered making UN statistics more available and intelligible using innovative visualisation tools and Many Eyes (http://www-958.ibm.com/) provides a very impressive interface for sharing data and creating visualisations.
World maps have become so common that they have even attracted satire. The Onion’s Atlas of the Planet Earth (The Onion 2007), contains a ‘Bono Awareness’ world map representing ‘the intensity with which artist Bono is aware of the plight and daily struggles of region’, with a categorisation ranging from ‘has heard of nation once’ through ‘moved enough by nations crisis to momentarily remove sunglasses’ to ‘cares about welfare of nation nearly as much as his own’.
There appears to be a gap in the market for free software tools that can be used across disciplinary boundaries to produce innovative, publication quality global visualisations. Within R there are great building blocks (particularly sp, maptools and fields) for spatial data but users previously had to go through a number of steps if they wanted to produce world maps of their own data. Experience has shown that difficulties with linking data and creating classifications, colour schemes and legends, currently constrains researchers’ ability to view and display global data. We aim to reduce that constraint to allow researchers to spend more time on the more important issue of what they want to display. The vision for rworldmap is to produce a package to facilitate the visualisation and mapping of global data. Because the focus is on global data, the package can be more specialised than existing packages, making world mapping easier, partly because it doesn’t have to deal with detailed local maps. Through rworldmap we aim to make it easy for R users to explore their global data and also to produce publication quality figures from their outputs.
rworldmap was partly inspired and largely funded by the UK Natural Environment Research Council (NERC) program Quantifying Uncertainty in Earth System Science (QUEST). This program brings together scientists from a wide range of disciplines including climate modellers, hydrologists and social scientists. It was apparent that while researchers have common tools for visualisation within disciplines, they tend to use different ones across disciplines and that this limits the sharing of data and methods necessary for truly interdisciplinary research. Within the project, climate and earth system modellers tended to use IDL, ecologists ArcGIS, hydrologists and social scientists Matlab and fisheries scientists R. With the exception of R, these software products cost thousands of pounds which acts as a considerable constraint on users being able to try out techniques used by collaborators. This high cost and learning curve of adopting new software tools hinders the sharing of data and methods between disciplines. To address this, part of the vision for rworldmap was to develop a tool that can be freely used and modified across a multi-disciplinary project, to facilitate the sharing of scripts, data and outputs. Such freely available software offers greater opportunity for collaboration with research institutes in developing countries that may not be able to afford expensive licenses.
rworldmap consists of tools to visualise global data and focuses on two types of data. Firstly, data that are referenced by country codes or names and secondly, data that are referenced on a grid.
There is a wealth of global country level data available on the internet including UN population data, and many global indices for, among others: Environmental Performance, Global Hunger and Multidimensional Poverty.
Data are commonly referenced by country names as these are the most easily recognised by users, but country names have the problem that vocabularies are not well conserved and many countries have a number of subtly different alternate names (e.g. Ivory Coast and Cote d’Ivoire, Laos and People’s Democratic Republic of Lao). To address this problem there are ISO standard country codes of either 2 letters, 3 letters or numeric, and also 2 letter FIPS country codes, so there is still not one universally adopted standard. rworldmap supports all of these country codes and offers tools to help when data are referenced by names or other identifiers.
Global datasets are frequently spatially referenced on a grid, because such gridded or raster data formats offer advantages in efficiency of data storage and processing. Remotely sensed data and other values calculated from it are most frequently available in gridded formats. These can include terrestrial or marine data or both.
There are many gridded data formats, here I will concentrate on two: ESRI GridAscii and netCDF.
ESRI GridAscii files are an efficient way of storing and transferring gridded data. They are straightforward text files so can be opened by any text editor. They have a short header defining the structure of the file (e.g. number, size and position of rows and columns), followed by a single row specifying the value at each grid cell. Thus they use much less space than if the coordinates for each cell had to be specified.
Example start of gridAscii file for a half degree global grid:
720
ncols 360
nrows -180
xllcorner -90
yllcorner 0.5
cellsize -999
NODATA_value -999 1 0 1 1 ... [all 259200 cell values]
NetCDF is a data storage file format commonly used by climate scientists and oceanographers. NetCDF files can be multi-dimensional, e.g. holding \((x,y)\) data for multiple attributes over multiple months, years, days etc. The package ncdf is good for reading data from netCDF files.
rworldmap has three core functions outlined below and others that are described later.
joinCountryData2Map()
joins user country data referenced by
country names or codes to a map to enable plotting
mapCountryData()
plots a map of country data
mapGriddedData()
plots a map of gridded data
To join the data to a map use joinCountryData2Map
. You will need to
specify the name of column containing your country identifiers
(nameJoinColumn
) and the type of code used (joinCode
) e.g. "ISO3"
for ISO 3 letter codes or "UN" for numeric country codes.
data(countryExData)
<- joinCountryData2Map( countryExData
sPDF joinCode = "ISO3"
,nameJoinColumn = "ISO3V10") ,
This code outputs, to the R console, a summary of how many countries are
successfully joined. You can specify verbose=TRUE
to get a full list
of countries. The object returned (named sPDF in this case) is of type
"SpatialPolygonsDataFrame"
from the package
sp. This object is required
for the next step, displaying the map.
If you only have country names rather than codes in your data, use
joinCode="NAME"
; you can expect more mismatches due to the greater
variation within country names mentioned previously. To address this you
can use the identifyCountries()
function described below, and change
any country names in your data that do not exactly match those in the
internal map.
To plot anything other than the default map, mapCountryData
requires
an object of class "SpatialPolygonsDataFrame"
and a specification of
the name of the column containing the data to plot:
data(countryExData)
<- joinCountryData2Map( countryExData
sPDF joinCode = "ISO3"
,nameJoinColumn = "ISO3V10")
,mapDevice() #create world map shaped window
mapCountryData(sPDF
nameColumnToPlot='BIODIVERSITY') ,
The mapGriddedData
function can accept either
an object of type "SpatialGridDataFrame"
, as defined in the
package sp
the name of an ESRI GridAscii file as a character string
a 2D R matrix or array (rows by columns)
rworldmap contains a
"SpatialGridDataFrame"
example that can be accessed and mapped as
shown in the code and figure below.
data(gridExData)
mapDevice() #create world map shaped window
mapGriddedData(gridExData)