Robin Lovelace
March 26, 2015
This course is brought to you the Consumer Data Research Centre (CDRC), a project based at the University of Leeds and UCL. It is funded by the ESRC’s (Big Data Network).
The course is based on “Introduction to visualising spatial data in R” (Lovelace and Cheshire 2014), a free, open source and evolving teaching resource. See github.com/Robinlovelace/Creating-maps-in-R.
Please contribute!
COFFEE
Source: Hadley Wickham. Further information: see “R beats Python! R beats Julia! Anyone else wanna challenge R?” (Matloff 2014)
“With the advent of “modern” GIS software, most people want to point and click their way through life. That’s good, but there is a tremendous amount of flexibility and power waiting for you with the command line. Many times you can do something on the command line in a fraction of the time you can do it with a GUI (Sherman 2008, p. 283)
If you get stuck? Just ask! E.g. stackoverflow.com/q/29066198/1694378:
@robinlovelace says:
I want to load only only the LineString, so this is what I do:
library(RCurl)
obj <- getURL("https://raw.githubusercontent.com/Robinlovelace/stplanr/master/inst/extdata/route_data.geojson")
writeLines(obj, "/tmp/obj.geojson")
obj <- readLines("/tmp/obj.geojson")
just_lines <- obj[14:(length(obj) - 28)]
just_lines[1] <- paste0("{", just_lines[1])
just_lines[length(just_lines)] <- "}"
writeLines(just_lines, "/tmp/just_lines.geojson")
How do I do this properly?
Read the data using jsonlite direct from the URL…
obj <- jsonlite::fromJSON("https://raw.githubusercontent.com/Robinlovelace/stplanr/master/inst/extdata/route_data.geojson")
Convert the first object in the collection to SpatialLines:
sl = SpatialLines(list(Lines(list(Line(obj$features[1,]$geometry$coordinates[[1]])),ID=1)))
If you cannot visualise your data, it is very difficult to understand your data. Conversely, visualisation will greatly aid in communicating your results.
Human beings are remarkably adept at discerning relationships from visual representations. A well-crafted graph can help you make meaningful comparisons among thousands of pieces of information, extracting patterns not easily found through other methods. … Data analysts need to look at their data, and this is one area where R shines. (Kabacoff, 2009, p. 45).
grid.raster(readPNG("~/repos/robinlovelace.github.io/figure/unnamed-chunk-53.png"))
Flexibility of ggplot2 - see robinlovelace.net
Before progressing further: Any questions?
Course materials are all available online from a GitHub repository. Click “Download ZIP” to download all the test data, ready to procede.
The main document to accompany this tutorial is a pdf within the main repository. This is to be made available for free worldwide - any comments/corrections welcome.
Bivand, Roger S, Edzer J Pebesma, and Virgilio Gómez-Rubio. 2013. Applied spatial data analysis with R. Vol. 747248717. Springer.
Cheshire, James, and Robin Lovelace. 2015. “Spatial data visualisation with R.” In Geocomputation, edited by Chris Brunsdon and Alex Singleton, 1–14. SAGE Publications. https://github.com/geocomPP/sdv.
Ihaka, Ross, and R Gentleman. 1996. “R: a language for data analysis and graphics.” Journal of Computational and Graphical … 5 (3): 299–314. http://www.tandfonline.com/doi/abs/10.1080/10618600.1996.10474713.
Lovelace, Robin, and James Cheshire. 2014. “Introduction to visualising spatial data in R.” National Centre for Research Methods Working Papers 14 (03). London: National Centre for Research Methods; EloGeo. https://github.com/Robinlovelace/Creating-maps-in-R.