{"id":893,"date":"2011-05-16T14:47:18","date_gmt":"2011-05-16T19:47:18","guid":{"rendered":"http:\/\/www.nomad.priv.at\/researchblog\/?p=893"},"modified":"2015-06-17T10:30:39","modified_gmt":"2015-06-17T15:30:39","slug":"mapping-points","status":"publish","type":"post","link":"http:\/\/www.nomad.priv.at\/researchblog\/?p=893","title":{"rendered":"Mapping points"},"content":{"rendered":"<p>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\u00a0circles is quite useful. After some trial &amp; error, here is some very basic code to do this &#8211;<\/p>\n<p>I have adapted a recipe from the <a href=\"http:\/\/geography.uoregon.edu\/geogr\/topics\/maps.htm\">Dept. of Geography, University of Oregon<\/a><\/p>\n<p># Load packages<br \/>\n<code>library(maps)<br \/>\nlibrary(maptools)<br \/>\nlibrary(RColorBrewer)<br \/>\nlibrary(classInt)<br \/>\nlibrary(gpclib)<br \/>\nlibrary(mapdata)<\/code><\/p>\n<p># 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)<br \/>\nSite,Para,Lat,Long<br \/>\n<code>plotvar &lt;- Var$Para<\/code><\/p>\n<p># Define number of colours to be used in plot<br \/>\n<code>nclr &lt;- 7<\/code><\/p>\n<p># Define colour palette to be used<br \/>\n<code>plotclr &lt;- brewer.pal(nclr,\"RdPu\")<\/code><\/p>\n<p># Define colour intervals and colour code variable for plotting<br \/>\n<code>class &lt;- classIntervals(plotvar, nclr, style = \"pretty\")<br \/>\ncolcode &lt;- findColours(class, plotclr)<\/code><\/p>\n<p># Plot the map with desired lat\/long coordinates and data points with colour coding and legend<br \/>\n<code>map(\"worldHires\", xlim = c(-125, -55), ylim = c(30, 83))<br \/>\npoints(Var$Long, Var$Lat, pch = 16, col= colcode, cex = 2)<br \/>\nlegend(\"bottomright\", legend = names(attr(colcode, \"table\")), fill = attr(colcode, \"palette\"), cex = 0.7, bty = \"n\")<\/code><\/p>\n<p>And here is the result:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.nomad.priv.at\/researchblog\/wp-uploads\/r_plotting.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1192\" src=\"http:\/\/www.nomad.priv.at\/researchblog\/wp-uploads\/r_plotting-230x300.jpg\" alt=\"r_plotting\" width=\"230\" height=\"300\" srcset=\"http:\/\/www.nomad.priv.at\/researchblog\/wp-uploads\/r_plotting-230x300.jpg 230w, http:\/\/www.nomad.priv.at\/researchblog\/wp-uploads\/r_plotting-785x1024.jpg 785w, http:\/\/www.nomad.priv.at\/researchblog\/wp-uploads\/r_plotting.jpg 831w\" sizes=\"auto, (max-width: 230px) 100vw, 230px\" \/><\/a><\/p>\n<div><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;\"><br \/>\n<\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0circles is quite useful. After some trial &amp; error, here is some very basic code to do this &#8211; I have adapted a recipe from the Dept. of Geography, University &hellip; <a href=\"http:\/\/www.nomad.priv.at\/researchblog\/?p=893\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Mapping points<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,4],"tags":[418,417,419,420,511],"class_list":["post-893","post","type-post","status-publish","format-standard","hentry","category-r","category-research","tag-colcode","tag-colour","tag-maps-library","tag-measurement-stations","tag-r"],"_links":{"self":[{"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=\/wp\/v2\/posts\/893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=893"}],"version-history":[{"count":4,"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=\/wp\/v2\/posts\/893\/revisions"}],"predecessor-version":[{"id":1672,"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=\/wp\/v2\/posts\/893\/revisions\/1672"}],"wp:attachment":[{"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=893"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nomad.priv.at\/researchblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}