- Claudia Engel, Department of Anthropology & Center for Interdisciplinary Digital Research
- Desktop GIS - ArcGIS Desktop. Install from here to take advantage of the Stanford Campus License (Stanford affiliated only). New: ArcGIS Pro
| ######################################## | |
| ### Intro to R NCCU, Aug 12-14, 2020 ### | |
| ######################################## | |
| # this is the workshop script | |
| # get working directory: | |
| getwd() # ctrl + enter to execute this line | |
| # just a test shift + ctrl + c > make a comment (more shortcuts under Tools > shortcuts) |
| # Original Idea and code by Jules Beley | |
| # https://github.com/julesbeley/Erasmusmap/blob/master/Erasmus.R | |
| # https://medium.com/@jules.beley/making-a-map-with-eu-data-on-r-erasmus-exchanges-by-country-3f5734dcd4ff | |
| library(tidyverse) | |
| library(maps) | |
| library(countrycode) | |
| download.file("http://data.europa.eu/euodp/data/uploads/EAC/SM_2012_13_20141103_01.csv", "erasmus.csv") # this may take a little while |
| ## | |
| ## this snippet loops through a directory with rasters and crates polygons | |
| ## using a call to gdal_polygonize.py | |
| ## (for Mac, with kynchaos GDAL framework) | |
| ## | |
| # make sure to not mess up the paths here! | |
| setwd("root/dir") | |
| indir <- "rasterdir-ending-with-slash/" | |
| outdir <- "polydir-ending-with-slash/" |
| # May have to install xckd fonts through FontBook. | |
| library(xkcd) | |
| # the data to make the bars | |
| df <- data.frame(x=c(1, 3), y=c(20, 2)) | |
| # the figures | |
| ratioxy <- diff(range(df$x)) / diff(range(df$y)) | |
| mapping <- aes(x, y, | |
| scale, |
| library(shiny) | |
| library(datasets) | |
| library(ggplot2) # load ggplot | |
| # Define server logic required to plot various variables against mpg | |
| shinyServer(function(input, output) { | |
| # Compute the forumla text in a reactive function since it is | |
| # shared by the output$caption and output$mpgPlot functions | |
| formulaText <- reactive(function() { |
| import pandas | |
| import rpy2.robjects as robjects | |
| from rpy2.robjects.packages import importr | |
| from rpy2.robjects.lib import grid | |
| from rpy2.robjects.lib import ggplot2 | |
| ## read in the distances to railroad (we calculated) | |
| neardist = pandas.read_csv('data/NearDistance.csv') | |
| ## convert to R dataframe, via Python Dictionary data type |
| library(maps) | |
| library(geosphere) | |
| library(plyr) | |
| library(ggplot2) | |
| library(sp) | |
| airports <- read.csv("http://www.stanford.edu/~cengel/cgi-bin/anthrospace/wp-content/uploads/2012/03/airports.csv", as.is=TRUE, header=TRUE) | |
| flights <- read.csv("http://www.stanford.edu/~cengel/cgi-bin/anthrospace/wp-content/uploads/2012/03/PEK-openflights-export-2012-03-19.csv", as.is=TRUE, header=TRUE) | |
| # aggregate nunber of flights |