R Maps
R Maps
Making maps in R
One way of visually representing data is to plot them on a geographical
map.
http://www.mpi.nl/departments/independent-research-
groups/evolutionary-processes/tools/mapping-with-r
Making maps in R
Making maps in R
Step 1: Install the non-standard libraries
On the MacOSX version you open the R application, select Package Installer from the
Packages & Data menu and choose Get List. When the list appears, scroll down to
and select maps and mapdata, tick the Install Dependencies checkbox (to be on the
safe side), and click Install Selected.
Making maps in R
In the Windows version...
Making maps in R
Test the installation
map()
Making maps in R
Step 2: Drawing maps: basics
map()
map.axes()
Making maps in R
Step 2: Drawing maps: basics
map()
map.axes()
map.scale()
Making maps in R
Step 2: Drawing maps: basics
Determines
background color
Determines the
foreground
(countries) color
2. Plot the languages onto the map using the function points() with the arguments
latitude and longitude of your object (remember: $)
Making maps in R
Step 5: Plotting data points onto a map
Making maps in R
Step 5: Plotting data points onto a map
Now suppose we wanted to display which languages had case marking and
which of the languages dont.
Making maps in R
Step 5: Plotting data points onto a map
1. Add a new column to the data frame filled with the value "gray"
mySAdata$my.col = "gray"
2. change the values of the $my.col column to "red" where the value for the $CASE column is "Y"
mySAdata$my.col[mySAdata$CASE == "Y"] = "red"
3. change the values of the $my.col column to "blue" where the value for the $CASE column is "N"
mySAdata$my.col[mySAdata$CASE == "N"] = "blue"
4. use the $my.col column of data as the values of the col attribute
points(mySAdata$LONGITUDE, mySAdata$LATITUDE, pch=20, col=mySAdata$my.col)
Making maps in R
Step 5: Plotting data points onto a map