R- geo examples
Get flash to fully experience Pearltrees
This is a short follow up on THIS posting.. I will briefly show how to use the dismo- and the googeVis package to plot species occurrences on an interactive Google map, like the one below ( HERE is the R-script) To leave a comment for the author, please follow the link and comment on his blog: theBioBucket* . R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization ( ggplot2 , Boxplots , maps , animation ), programming ( RStudio , Sweave , LaTeX , SQL , Eclipse , git , hadoop , Web Scraping ) statistics ( regression , PCA , time series , ecdf , trading ) and more...
As part of my Google Summer of Code, I am also working on another package for R called rvertnet . This package is a wrapper in R for VertNet websites. Vertnet is a vertebrate distributed database network consisting of FishNet2 , MaNIS , HerpNET , and ORNIS . Out of that currently Fishnet, HerpNET and ORNIS have their v2 portals serving data. rvertnet has functions now to access this data and import them into R data frames. Some of my lab mates faced a difficulty in downloading data for Scrub Jay ( Aphelocoma spp. ) due to large number of records (220k+) on ORNIS, so decided to try using rvertnet package which was still in development that time. The package really helpe and got the results quickly.
In 1854 there was a massive cholera outbreak in Soho, London – in three days over 120 people died from the disease. Famously, John Snow plotted the locations of the deaths on a map and found they clustered around a pump in Broad Street – he suggested that the pump be taken out of service – thus helping to end the epidemic. This then helped him formulate his theory of the spread of cholera by dirty water. This analysis is famous as it is often considered to be:
I have been using R (a free statistics and graphics software package) now for the past four years or so and I have seen it become an increasingly powerful method of both analysing and visualising spatial data. Crucially, more and more people are writing accessible tutorials ( see here ) for beginners and intermediate users and the development of packages such as ggplot2 have made it simpler than ever to produce fantastic graphics. You don’t get the interactivity you would with conventional GIS software such as ArcGIS when you produce the visualisation but you are much more flexible in terms of the combinations of plot types and the ease with which they can be combined. It is, for example, time consuming to produce multivariate symbols (such as those varying in size and colour) in ArcGIS but with R it is as simple* as one line of code. I have, for example, been able to add subtle transitions in the lines of the migration map above.
The map above shows the routes flown by the top 7 airlines (by international passenger distance flown) . The base map shows large urban areas and I have attempted to make it look a bit like the beautiful “ Earth at Night ” composite image produced by NASA. You can clearly see a relationship between where people live and where the big carriers fly to across Europe and the US but India and much of China have relatively few routes. I expect much of the slack is picked up by smaller airlines in these countries but they must represent key growth areas the world economy becomes increasingly driven by the east. This map isn’t meant to be comprehensive- I just wanted to make another example of a visualisation with ggplot2.
I recently stumbled upon a fascinating dataset which contains digitised information from the log books of ships (mostly from Britain, France, Spain and The Netherlands) sailing between 1750 and 1850. The creation of this dataset was completed as part of the Climatological Database for the World’s Oceans 1750-1850 (CLIWOC) project. The routes are plotted from the lat/long positions derived from the ships’ logs. I have played around with the original data a little to clean it up (I removed routes where there was a gap of over 1000km between known points, and only mapped to the year 1800). As you can see the British (above) and Spanish (below) had very different trading priorities over this period. What fascinates me most about these maps is the thousands (if not millions) of man hours required to create them.
On September 14th 2011 Dr Alec Stephenson gave a talk on exploring spatial data with R ( see Meetup page ). The video of the talk is now available online. The talk provides a non-mathematical and entirely equation-free talk on visualizing and analysing spatial data in R. Alec discusses the different types of spatial data, the main R packages needed for the analysis of those types, and present a selection of examples from a wide range of application areas.
As I was getting a root canal last week, my dental X-Rays reminded me anew of an optical illusion that stumped us for a short time recently when we were developing our heatmapping engine. My X-Rays, before during and after a recent root canal. They reminded me, of course, about cartography. Dentists, or at least dental radiologists looking at dental X-Rays, are probably familiar with the pesky phenomena of Mach Banding . It is an optical illusion that presents itself when contrasting tones are viewed right next to each other in the context of lightness gradients.
A new package OpenStreetMap has been released to CRAN this week which is designed to allow you to easily add satellite imagery, or open street maps to your plots. Raster maps are a great way to add context to your spatial data with a minimum outlay of effort. The syntax in OpenStreetMap is fairly simple, just give it a bounding box in lat/long and it will download a high quality raster image ready for plotting library(OpenStreetMap) library(rgdal) map <- openmap(c(70,-179), c(-70,179)) plot(map)
Creating web applications with Rwui The information that Rwui needs in order to create a web application for running an R script is entered on a series of web forms. Using these forms the statistician designs the web application they wish to construct. After entering a title and introductory text for the application, the input items that will appear on the application's web page are selected.
Today I needed to cut out a rectangle of geologic data from a state-wide map in an AEA coordinate system, using a bounding box from a UTM zone 10 region, with the output saved in UTM zone 10 coordinates. PostGIS makes this type of operation very simple via spatial SQL. Note the special syntax that PostgreSQL uses for referencing variables. Spatial SQL Example -- set our query geometry as a variable for use later \ SET query_geom ST_Transform ( SetSRID ( ST_MakeBox2d ( ST_Point ( 675461 , 4168366 ) , ST_Point ( 749990 , 4260786 ) ) , 26910 ) , 9001 ) -- save the result of our query to a temp table for export CREATE TEMP TABLE tt AS SELECT ST_Transform ( ST_Intersection ( wkb_geometry , :query_geom ) , 26910 ) AS wkb_geometry , ptype , ptype_full , gen_type , note FROM cageo JOIN cageo_legend USING ( ptype ) WHERE ST_Intersects ( wkb_geometry , :query_geom ) ;
Rwui running on new server, Java 1.6 and Tomcat 6, or later, now required to run webapps created by Rwui. Copy of Rwui, with older Java and Tomcat requirements for running the webapps it creates, still available at http://xenakis.mrc-bsu.cam.ac.uk/Rwui, but please note old version has not been updated with recent additions (on 20/06/12). Window's users please note points 13.1 and 15.1 in the Help file. A user friendly web interface for an R script means your script can be used by anyone, even if they have no knowledge of R. Rwui creates web applications for you for running R scripts. All the code is generated automatically so that a fully functional web interface for an R script can be downloaded and up and running in a matter of minutes.
..The dismo package is awesome: with some short lines of code you can read & map species distribution data from GBIF (the global biodiversity information facility) easily: Read more » To leave a comment for the author, please follow the link and comment on his blog: theBioBucket* . R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization ( ggplot2 , Boxplots , maps , animation ), programming ( RStudio , Sweave , LaTeX , SQL , Eclipse , git , hadoop , Web Scraping ) statistics ( regression , PCA , time series , ecdf , trading ) and more... <p style="text-align:right;color:#A8A8A8"></p>
(1) for producing html code for a Google Map with R-package googleVis do something like: (2) then just copy-paste the html to your blog or website after customizing for your purpose.. To leave a comment for the author, please follow the link and comment on his blog: theBioBucket* . R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization ( ggplot2 , Boxplots , maps , animation ), programming ( RStudio , Sweave , LaTeX , SQL , Eclipse , git , hadoop , Web Scraping ) statistics ( regression , PCA , time series , ecdf , trading ) and more... <p style="text-align:right;color:#A8A8A8"></p>
Below is a link to a pdf (compiled with the amazing knitr package) and some accompanying data for a recent short course I gave on basic spatial data import/analysis/visualization in R. The class was only two hours and some of the participants were being exposed to R for the first time so the material is limited. The class was a follow up to a previous one I did on ArcGIS. The idea was to show how to perform the same functions in R and ArcGIS and then let users decide which worked best for them (I use R for about 90% of my spatial analysis and data handling but find ArcGIS (or some GUI based GIS) pretty essential for that last 10%). The content/main points of the course: