Skip to content

Instantly share code, notes, and snippets.

@rrodrigueznt
Last active March 13, 2019 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrodrigueznt/76d1c71da1da373031e69d33bbbad4a3 to your computer and use it in GitHub Desktop.
Save rrodrigueznt/76d1c71da1da373031e69d33bbbad4a3 to your computer and use it in GitHub Desktop.
#
options(stringsAsFactors=F)
options(digits=2)
#
#
# returns string w/o leading whitespace
trim.leading <- function (x) sub("^\\s+", "", x)
#
# returns string w/o trailing whitespace
trim.trailing <- function (x) sub("\\s+$", "", x)
#
# returns string w/o leading or trailing whitespace
trim <- function (x) gsub("^\\s+|\\s+$", "", x)
#
#
library(openxlsx) #to use read.xlsx()
library(readxl) #to read Excel's sheets names and *.xls files
library(dplyr) #to filter, order, rarrange...
#
##
## https://www.sharpsightlabs.com/blog/map-oil-production-country-r/
## as an example for creating maps
##
library(tidyverse)
library(sf)
library(rvest)
library(stringr)
library(scales)
#
#IGFAECR <- file.path("/Users/rrodriguez/Universidade de Santiago de Compostela/SALGADO LOPEZ CARLOS ALBERTO - IGFAE/GlobalTalent/IGFAEGlobalTalent2018/IGFAECR.appl.csv")
IGFAECR <- file.path("C:/Users/Ricardo Rodríguez/Universidade de Santiago de Compostela/IGFAE-EB - Documents/HumanCapital/Internal_postdoc/2018/MdM_auger/appl.IGFAECR.xls")
#
IGFAECRdata <- readxl::read_excel(IGFAECR, sheet = "ajo15499299531008483")
#
IGFAECRdata$LastUpdated <- as.Date(IGFAECRdata$LastUpdated)
IGFAECRdata$Received <- as.Date(IGFAECRdata$Received)
#
IGFAECRdata[,c('Uid','Name','Degree_Institution')]
#
as.data.frame(IGFAECRdata[,c('Uid')])
#
#AJO <- file.path("/Users/rrodriguez/Universidade de Santiago de Compostela/SALGADO LOPEZ CARLOS ALBERTO - IGFAE/GlobalTalent/IGFAEGlobalTalent2018/AJOuid.xlsx")
AJO <- file.path("C:/Users/Ricardo Rodríguez/Universidade de Santiago de Compostela/IGFAE-EB - Documents/GlobalTalent/IGFAEGlobalTalent2018/AJOuid.xlsx")
#
AJOdata <- openxlsx::read.xlsx(AJO, sheet = "people")
#
IGFAECRdataAll <- merge(IGFAECRdata, AJOdata)
#
table(IGFAECRdataAll$gender)
#
prop.table(table(IGFAECRdataAll$gender))
#
anti_join(IGFAECRdataAll, map.world, by = c('countryDegree' = 'region'))
#
IGFAECRbyCountry <- as.data.frame(table(IGFAECRdataAll$countryDegree), stringsAsFactors = default.stringsAsFactors())
#
names(IGFAECRbyCountry) <- c('countryDegree','nApplications')
#
map.IGFAECR <- left_join(map.world, IGFAECRbyCountry, by = c('region' = 'countryDegree'))
#
anti_join(IGFAECRbyCountry, map.world, by = c('countryDegree' = 'region'))
#
ggplot(map.IGFAECR, aes( x = long, y = lat, group = group )) + geom_polygon(aes(fill = nApplications))
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment