Mapping points

[This article was first published on Greg's Research » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Since I look at mercury concentrations at different measurement stations in North America, visualization using a map with values (of your favourite parameter) plotted as colour-coded circles is quite useful. After some trial & error, here is some very basic code to do this –

I have adapted a recipe from the Dept. of Geography, University of Oregon

# Load packages
library(maps) library(maptools) library(RColorBrewer) library(classInt) library(gpclib) library(mapdata)

# Define vector with the values that you would like to see plotted at desired lat/long. Your csv input file loaded as dataframe (Var) must feature the following columns (Site is optional, but useful for labeling)
plotvar <- Var$Para

# Define number of colours to be used in plot
nclr <- 7

# Define colour palette to be used
plotclr <- brewer.pal(nclr,"RdPu")

# Define colour intervals and colour code variable for plotting
class <- classIntervals(plotvar, nclr, style = "pretty") colcode <- findColours(class, plotclr)

# Plot the map with desired lat/long coordinates and data points with colour coding and legend
map("worldHires", xlim = c(-125, -55), ylim = c(30, 83)) points(Var$Long, Var$Lat, pch = 16, col= colcode, cex = 2) legend("bottomright", legend = names(attr(colcode, "table")), fill = attr(colcode, "palette"), cex = 0.7, bty = "n")

And here is the result:

R plotting points on geographical map

To leave a comment for the author, please follow the link and comment on their blog: Greg's Research » R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)