Tuesday, May 26, 2015

Summary

This is a reproducible paper, that tries to introduce the reader on friendly "hello world Gis", using some R packages, who I'd like to highlight is from Robinlovelace's studies who could be found at https://github.com/Robinlovelace?tab=repositories. Thanks Robin.

Preparing Environment - Install Packages - 1/2

# The order is important here, take care.

#1) Creating a vector with the name of the basic packages to install
pkgs <- c("devtools", "shiny", "rgdal",
          "rgeos", "ggmap", "raster")


#2) Install these packages over the vector
install.packages(pkgs, repos = "http://cran.us.r-project.org")

Preparing Environment - Install Packages - 2/2

#3) Import devtools library
library(devtools)

#4) Creating a second vector with the name of robinlovelace's packages. 
#Thanks Robin :)
gh_pkgs <- c("rstudio/leaflet", 
             "robinlovelace/stplanr") 


#5) Install them
install_github(gh_pkgs)


#6) Attach them to library
lapply(c(pkgs, "leaflet", "stplanr"), 
       library, character.only = T)

A global var (named: downloadLink), as an example

Downloading data

download.file(downloadLink, paste0(getwd(),"/data.zip"))

Unziping data

unzip("data.zip")

Reading The shape file

lnd <- shapefile("./EBM_v91_sample/StatisticalUnits/NUTS_3.shp")

Showing The data content

print(class(lnd)) 
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"

Using google geocode to access NUIG location

locationNUIG <- geocode("NUIG",sensor = TRUE)

Using Robinlovelace API to do the great magic :)

library(leaflet)
mp <- leaflet(data=locationNUIG)
mp <- addTiles(map = mp)
mp <- addCircles(mp, radius = 40)
mp <- addPopups(mp,popup = "That's NUIG :)")
mp

References

Conclusion

That's can be basic, rudimentary but need to be shared, because is very fun! Thank you :)