Mapping points

May 16, 2011

(This article was first published on Greg's Research » R, and kindly contributed to R-bloggers)

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

# 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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , ,

Comments are closed.

Search R-bloggers


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)