rworldmap vignette Andy South October 5, 2012

Similar documents
rworldmap FAQ Andy South November 12, combine rworldmap with other packages classint and RColorBrewer? 11

Package rworldmap. August 29, 2016

Visualising Spatial Data UCL Geography R Spatial Workshop Tuesday 9 th November 2010 rspatialtips.org.uk

Analysing Spatial Data in R: Vizualising Spatial Data

The Economist rate card 2017 (GBP)

The Economist rate card 2017 (USD)

Package Grid2Polygons

Ontario Cancer Profiles User Help File

Data Visualization (CIS 468)

ScholarOne Manuscripts. Publisher Level Reporting Guide

Advanced Multivariate Continuous Displays and Diagnostics

Global modelling of air pollution using multiple data sources

Using Spatial Data in a Desktop GIS; QGIS 2.8 Practical 2

More information from: dry-cleaning-and-laundry-services-global-marketreport-2018-including

GRAPHING IN EXCEL EXCEL LAB #2

Practical 11: Interpolating Point Data in R

Navigator for ArcGIS Presented by

Statistical Software Camp: Introduction to R

-In windows explorer navigate to your Exercise_4 folder and right-click the DEC_10_SF1_P1.csv file and choose Open With > Notepad.

International Packets

Items exceeding one or more of the maximum weight and dimensions of a flat. For maximum dimensions please see the service user guide.

PREREQUISITES FOR EXAMPLES

Global modelling of air pollution using multiple data sources

Safety. Introduction

Broadband access technologies and their introduction in fixed networks of Uzbekistan

Appendices. Appendix A. Plots and Quantile Regression Using R and Stata Commands. Introduction

Internet Accessibility Continental Comparison. Marcus Leaning Professor of Digital Media Education University of Winchester U.K.

hvpcp.apr user s guide: set up and tour

Shatterbelt Regions Data Set ( ) Version 1.1 (last revised 27 March 2000)

PM Sync User Manual 31 July 2012

World Broadband Statistics: A Short Report from Global Broadband Statistics

3ie evidence gap maps platform Automatic importer guide

Emergency Communications and Disaster Management

Supplier Invoice Submission Guide. English

Power Analyzer Firmware Update Utility Version Software Release Notes

Step by Step GIS. Section 1

Mapping Census data in QGIS

Mapping 2001 Census Data Using ArcView 3.3

Package superheat. February 4, 2017

Joining data from an Excel spreadsheet

Opportunities and Challenges in a World of Global Information

Capacity Building in the Context of the Comprehensive Nuclear-Test-Ban Treaty

SAMPLE. Excel 2010 Advanced. Excel 2010 Advanced. Excel 2010 Advanced Page 1

Index Page 1 of 10. Index test size A6. Background. Page 2. Page 3

Index Page 1 of 13. Index test size A6. Background. Page 2. Page 3

THE STATE OF ICT IN SOUTH AND SOUTH-WEST ASIA

General Ledger Integration

ScholarOne Abstracts. Review Administrator Guide

You will begin by exploring the locations of the long term care facilities in Massachusetts using descriptive statistics.

A stratum is a pair of surfaces. When defining a stratum, you are prompted to select Surface1 and Surface2.

PowerPoint 2013 Advanced. PowerPoint 2013 Advanced SAMPLE

Excel 2013 Foundation. Excel 2013 Foundation SAMPLE

Royal Mail International Update February 2018

GemTools Documentation

Global entertainment and media outlook Explore the content and tools

TELECOMS SERVICES FOR SMALL AND MEDIUM-SIZED ENTERPRISES: WORLDWIDE FORECAST

Laptops and Netbooks: Mobile Broadband Traffic Across Regions

IPTV Statistics market analysis

Royal Mail International Update December 2018

CHART CATALOGUE. of Transas Marine (UK) Ltd in Great Britain and other jurisdictions.

Create a Color-Shaded Map

265m. Asia. Pacific. 900m 350m 67% 31m 61% #betterfuture. 102% INCREASE the most of any region. Cellular IoT smart city connections

Excel 2010 Advanced. Excel 2010 Advanced SAMPLE

USER GUIDE. ReSAKSS-Asia. Map Tool. Creative Commons BY-SA 3.0

What s New: Sage 200 Evolution Version 9.10

Global Mobile Data Forecast, : Still Growing and No Signs of Slowing Market Study First Quarter 2017

Excel 2010 Foundation. Excel 2010 Foundation SAMPLE

World Summit on the Information Society (WSIS) and the Digital Divide

SAMPLE. PowerPoint 2010 Advanced. PowerPoint 2010 Advanced. PowerPoint 2010 Advanced Page 1

Kernel Wt. 104,577, ,563, ,141, ,212, ,145, ,357, Crop Year

Biorisk Management Professional Certification Program. Maureen Ellis Executive Director International Federation of Biosafety Associations

PowerPoint 2013 Advanced. PowerPoint 2013 Advanced SAMPLE

Excel 2016 Foundation SAMPLE

Prisma II High Density Dual Reverse Receiver (HD-RXR) Software- Devtype Mismatch Technical Bulletin

ScholarOne Abstracts. Reviewer User Guide

OFFICE SERVICES AND SERVERS MVP Independent SharePoint Consultant, SharePoint MVP and Top 25 SharePoint Influencer Worldwide.

Royal Mail International Update October 2017

Odin. SMB Cloud InsightsTM GLOBAL

Exercise Producing Thematic Maps for Dissemination

ESPON Online Mapping Tool. RIMAP User's Manual

LPWA NETWORKS FOR IoT: WORLDWIDE TRENDS AND FORECASTS

QGIS Workshop Su Zhang and Laura Gleasner 11/15/2018. QGIS Workshop

SW6000 Conference Management Software, Version 6.5 SW6000-CDA. CDA Conference Display Shure Incorporated

Step 1: New Portal User User ID Created Using IdentityIQ (IIQ)

Advanced Plotting Di Cook, Eric Hare May 14, 2015

Highlights of Directory Search Report Spring Compiled and Edited by David Armstrong

Note: All slides are under NDA

Delivering more. A guide to our Christmas mailing services

Pay-TV services worldwide: trends and forecasts PAY-TV SERVICES WORLDWIDE: TRENDS AND FORECASTS

Arc Pro. Wallboard. User Guide. Version 6.1.0

International Business Parcels Rate card

Welcome to. International Trade and Market Access Online WTO trade statistics illustrated

Preference Manager Pages

Will it one day be green to shun the internet?

M2M device connections and revenue: worldwide forecast

RELEASE NOTES. .ini file utility, version 1.0. Release Notes:.ini File Utility, Version 1.0. Purpose and Summary. Purpose. Summary

Session 9. Introduction

50GBASE-FR/LR, 100GBASE-DR, 200GBASE-DR4/ LR4/FR4 & 400GBASE-LR8/FR8/DR4 Optical Conformance and Characterization Solution for Sampling Scopes

Excel 2016 Advanced SAMPLE

International Business Mail Rate Card

Transcription:

rworldmap vignette Andy South October 5, 2012 rworldmap is a package for visualising global data, concentrating on data referenced by country codes or gridded at half degree resolution. Funded by : Contents 1 Introduction 2 2 Mapping your own country level data 3 2.1 Reading data into R.......................... 4 2.2 Joining data to a country map..................... 4 2.3 Displaying a countries map....................... 4 3 Mapping your own half degree gridded data 5 4 Aggregating half degree gridded data to a country level 6 5 Aggregating country level data to global regions 6 6 Map display options common across the plotting methods 8 7 Example maps with settings modified 9 8 Bubble plots 12 Centre for Environment, Fisheries and Aquaculture Science (Cefas), Lowestoft, NR33 OHT, UK. southandy at gmail.com 1

9 Combining rworldmap with other packages classint and RColor- Brewer 13 1 Introduction Package rworldmap is loaded by > library(rworldmap) This vignette shows a few examples of the main rworldmap functions to get you started. To access the full help system, type?rworldmap in the R console. The functions are designed to operate with few specified parameters in which case default values are used, but can also accept user input to allow flexibility e.g. in size, data categorisation, and colour schemes. Figure 1: An example from mapcountrydata 2

Figure 2: An example from mapgriddeddata 2 Mapping your own country level data To map your own data you will need it in columns with one row per country, one column containing country identifiers, and other columns containing your data. The mapping process then involves 3 steps (or 2 if your data are already in an R dataframe). 1. read data into R 2. join data to a map ( using joincountrydata2map() ) 3. display the map ( using mapcountrydata() ) There is an example dataset within the package that can be accessed using the data command, and the command below shows how to display a subset of the rows and columns. > data(countryexdata) > countryexdata[5:10,1:5] ISO3V10 Country EPI_regions 5 ARM Armenia Middle East and North Africa 6 AUS Australia East Asia and the Pacific 7 AUT Austria Europe 8 AZE Azerbaijan Central and Eastern Europ 9 BDI Burundi Sub-Saharan Africa 10 BEL Belgium Europe GEO_subregion Population2005 5 Eastern Europe 3016.3 6 Australia + New Zealand 20155.1 7 Western Europe 8189.4 8 Eastern Europe 8410.8 3

9 Eastern Africa 7547.5 10 Western Europe 10419.1 2.1 Reading data into R To read in your own data from a space or comma delimited text file you will need to use : read.csv(filename.csv) or read.txt(filename.txt), type?read.table from the R console to get help on this. 2.2 Joining data to a country map To join the data to a map use joincountrydata2map, and 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. If you only have country names rather than codes use join- Code= NAME, you can expect more mismatches because there is greater variation in what a single country may be named. > data(countryexdata) > spdf <- joincountrydata2map( countryexdata +, joincode = "ISO3" +, namejoincolumn = "ISO3V10") 149 codes from your data successfully matched countries in the map 0 codes from your data failed to match with a country code in the map 94 codes from the map weren't represented in your data You can see that a summary of how many countries are successfully joined is output to the console. 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. 2.3 Displaying a countries map mapcountrydata requires as a minimum a SpatialPolygonsDataFrame object and a specification of the name of the column containing the data to plot. The first line starting par... below and in subsequent plots simply ensures the plot fills the available space on the page. > par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > mapcountrydata( spdf, namecolumntoplot="biodiversity" ) 4

In this small map the default legend is rather large. This could be fixed by calling the addmaplegend function as in the code below. > mapparams <- mapcountrydata( spdf, namecolumntoplot="biodiversity" +, addlegend=false ) > do.call( addmaplegend, c(mapparams, legendwidth=0.5, legendmar = 2)) Using do.call allows the output from mapcountrydata to be used in addmaplegend to ensure the legend matches the map while also allowing easy modification of extra parameters such as legendwidth. 3 Mapping your own half degree gridded data The mapgriddeddata function can accept either 1. an object of type SpatialGridDataFrame, as defined in the package sp 2. the name of an ESRI gridascii file as a character string 3. a 2D R matrix or array (rows by columns) rworldmap contains an example SpatialGridDataFrame that can be accessed and printed as shown in the code below. > par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > data(gridexdata) > mapgriddeddata(gridexdata) 5

4 Aggregating half degree gridded data to a country level maphalfdegreegridtocountries() takes a gridded input file, and aggregates, to a country level and plots the map, it accepts most of the same arguments as map- CountryData(). In the example below the trick from above of modifying the legend using addmaplegend() is repeated. > par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > mapparams <- maphalfdegreegridtocountries(gridexdata, addlegend=false) > do.call( addmaplegend, c(mapparams, legendwidth=0.5, legendmar = 2)) 5 Aggregating country level data to global regions Country level data can be aggregated to global regions specified by regiontype in country2region which outputs as text, and mapbyregion which produces a map plot. The regional classifications available include SRES, GEO3, Stern and GBD. > #Using country2region to calculate mean ENVHEALTH in Stern regions. > sternenvhealth <- country2region(infile=countryexdata 6

+,namedatacolumn="envhealth" +,joincode="iso3" +,namejoincolumn="iso3v10" +,regiontype="stern" +,FUN="mean" + ) > print(sternenvhealth) meanenvhealthbystern Australasia 78.86000 Caribbean 82.18000 Central America 82.78750 Central Asia 77.24000 East Asia 75.52308 Europe 95.19762 North Africa 77.38000 North America 98.70000 South America 83.62727 South Asia 61.96000 South+E Africa 49.06316 West Africa 36.99474 West Asia 82.78000 > par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > mapbyregion( countryexdata +, namedatacolumn="climate" +, joincode="iso3" +, namejoincolumn="iso3v10" +, regiontype="stern" +, FUN="mean" + ) 7

6 Map display options common across the plotting methods The following arguments can be specified to alter the appearance of your plots. ˆ catmethod method for categorisation of data pretty, fixedwidth, diverging, logfixedwidth, quantiles, categorical, or a numeric vector defining breaks. ˆ numcats number of categories to classify the data into, may be modified if that exact number is not possible for the chosen catmethod. ˆ colourpalette a string describing the colour palette to use, choice of : 1. palette for the current palette 2. a vector of valid colours, e.g. c( red, white, blue ) or output from RColour- Brewer 3. one of heat, diverging, white2black, black2white, topo, rainbow, terrain, negpos8, negpos9 ˆ addlegend set to TRUE for a default legend, if set to FALSE the function addmaplegend() or addmaplegendboxes() can be used to create a more flexible legend. ˆ mapregion a region to zoom in on, can be set to a country name from getmap()$name or one of eurasia, africa, latin america, uk, oceania, asia 8

7 Example maps with settings modified This demonstrates how continuous data can be put into categories outside of the rworldmap functions and how a user defined colour palette can be used. Because the catmethod= categorical was used a legend with separate boxes rather than a colour bar is added. 9

> par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > #joining the data to a map > spdf <- joincountrydata2map(countryexdata, + joincode = "ISO3", + namejoincolumn = "ISO3V10" + ) > #creating a user defined colour palette > op <- palette(c('green','yellow','orange','red')) > #find quartile breaks > cutvector <- quantile(spdf@data[["biodiversity"]],na.rm=true) > #classify the data to a factor > spdf@data[["biocategories"]] <- cut(spdf@data[["biodiversity"]] +, cutvector +, include.lowest=true ) > #rename the categories > levels(spdf@data[["biocategories"]]) <- c('low', 'med', 'high', 'vhigh') > #mapping > mapcountrydata( spdf +, namecolumntoplot='biocategories' +, catmethod='categorical' +, maptitle='biodiversity categories' +, colourpalette='palette' +, oceancol='lightblue' +, missingcountrycol='white' + ) Figure 3: An example of a categorical map produced from mapcountrydata 10

You can zoom in on a map by specifying mapregion= Eurasia (or by specifiying xlim and ylim) and the country outlines can be changed by bordercol= black. > par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > mapcountrydata( spdf +, namecolumntoplot='biocategories' +, catmethod='categorical' +, maptitle='biodiversity categories' +, colourpalette='palette' +, oceancol='lightblue' +, missingcountrycol='white' +, mapregion='eurasia' +, bordercol='black' + ) > ## At end of plotting, reset palette to previous settings: > palette(op) > 11

8 Bubble plots The mapbubbles function allows flexible creation of bubble plots on global maps. You can specifiy data columns that will determine the sizing and colouring of the bubbles (using namezsize and namezcolour ). The function also accepts other spatialdataframe objects or data frames as long as they contain columns specifiying the x and y coordinates. The interactive function identifycountries allows the user to click on bubbles and the country name and optionally an attribute variable will be printed on the map. > par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > mapbubbles( df=getmap() +, namezsize="pop_est" +, namezcolour="geo3major" +, colourpalette='rainbow' +, oceancol='lightblue' +, landcol='wheat' + ) > 12

9 Combining rworldmap with other packages classint and RColorBrewer Whilst rworldmap sets many defaults internally there is also an option to use other packages to have greater flexibility. In this example the package classint is used to create the classification and RColorBrewer to specify the colours. The following page demonstrates how multiple maps can be generated in the same figure and shows a selection of different RColorBrewer palettes. > par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > library(classint) > library(rcolorbrewer) > #getting example data and joining to a map > data("countryexdata",envir=environment(),package="rworldmap") > spdf <- joincountrydata2map( countryexdata +, joincode = "ISO3" +, namejoincolumn = "ISO3V10" +, mapresolution='coarse' + ) > #getting class intervals using a 'jenks' classification in classint package > classint <- classintervals( spdf[["epi"]], n=5, style="jenks") > catmethod = classint[["brks"]] > #getting a colour scheme from the RColorBrewer package > colourpalette <- brewer.pal(5,'rdpu') > #calling mapcountrydata with the parameters from classint and RColorBrewer > mapparams <- mapcountrydata( spdf +, namecolumntoplot="epi" +, addlegend=false +, catmethod = catmethod +, colourpalette = colourpalette ) > do.call( addmaplegend +, c( mapparams +, legendlabels="all" +, legendwidth=0.5 +, legendintervals="data" +, legendmar = 2 ) ) 13

14

> #uses spdf from the previous chunk > > op <- par(fin=c(7,9),mfcol=c(5,2),mai=c(0,0,0.2,0),xaxs="i",yaxs="i") > brewerlist <- c("greens","greys","oranges","orrd" +,"PuBuGn","Purples","YlGn","YlGnBu","YlOrBr","YlOrRd") > for(i in 1:10) + { + #getting a colour scheme from the RColorBrewer package + colourpalette <- brewer.pal(7,brewerlist[i]) + + #calling mapcountrydata with the parameters from RColorBrewer + mapparams <- mapcountrydata( spdf +, namecolumntoplot="climate" +, addlegend=false +, colourpalette=colourpalette +, maptitle=brewerlist[i] ) + do.call( addmaplegend +, c(mapparams,horizontal=false,legendlabels="none",legendwidth=0.7)) + } > par(op) 15 Figure 4: Different RColorBrewer palettes applied to the same data