Skip to content

Instantly share code, notes, and snippets.

Giorgio Comai giocomai

Block or report user

Report or block giocomai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sibiu_1934_map.Rmd
---
title: "Sibiu 1934 historic map"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("tidyverse")
library("leaflet")
library("leaflet.opacity")
@giocomai
giocomai / cartograms_italy_leftovers.Rmd
Last active Jun 9, 2019
Unsuccesful or partly successful attempts removed from a post on cartograms and EU elections in Italy
View cartograms_italy_leftovers.Rmd
```{r eval = FALSE}
partito_facet_tm <- carto_partiti_combo %>%
tm_shape() +
tm_polygons(col = "perc",
palette = "YlGnBu") +
@giocomai
giocomai / Nations_in_transit_animated.R
Last active Mar 24, 2019
Nations in transit animated line chart
View Nations_in_transit_animated.R
if (!require("pacman")) install.packages("pacman")
pacman::p_load("tidyverse")
pacman::p_load("gganimate")
pacman::p_load("gifski")
nit <- tibble::tribble(
~Country, ~`2001`, ~`2002`, ~`2003`, ~`2004`, ~`2005`, ~`2006`, ~`2007`, ~`2008`, ~`2009`, ~`2010`, ~`2011`, ~`2012`, ~`2013`, ~`2014`, ~`2015`, ~`2016`, ~`2017`, ~`2018`,
"Albania", 4.42, 4.25, 4.17, 4.13, 4.04, 3.79, 3.82, 3.82, 3.82, 3.93, 4.04, 4.14, 4.25, 4.18, 4.14, 4.14, 4.14, 4.11,
"Bosnia Herzegovina", 5.17, 4.83, 4.54, 4.29, 4.18, 4.07, 4.04, 4.11, 4.18, 4.25, 4.32, 4.36, 4.39, 4.43, 4.46, 4.5, 4.54, 4.64,
"Bulgaria", 3.42, 3.33, 3.38, 3.25, 3.18, 2.93, 2.89, 2.86, 3.04, 3.04, 3.07, 3.14, 3.18, 3.25, 3.29, 3.25, 3.36, 3.39,
@giocomai
giocomai / extract_armenia_census_2011.R
Created Dec 22, 2018
Extracts Armenia 2011 census data for all settlements from pdf file issued by Armenia's statistical office
View extract_armenia_census_2011.R
library("tabulizer")
library("tidyverse")
dir.create("data", showWarnings = FALSE)
dir.create(file.path("data", "original_files"), showWarnings = FALSE)
census_2011_pdf_url <- "https://www.armstat.am/file/article/1._bajin_1_182-311.pdf"
census_2011_pdf_file <- file.path("data", "original_files", "census_2011.pdf")
if (file.exists(census_2011_pdf_file)==FALSE) {
@giocomai
giocomai / datacommons_json_to_csv.R
Last active Oct 1, 2018
Convert to csv json from FactChecks and Data Commons.org
View datacommons_json_to_csv.R
if (!require("pacman")) install.packages("pacman")
pacman::p_load("jsonlite")
pacman::p_load("tidyverse")
#https://www.datacommons.org/docs/download.html
text <- readLines(con = "fact_checks_20180502.txt")
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed('<script type=\"application/ld+json\">'))
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed("</script>"))
txtList <- purrr::map(.x = text, .f = fromJSON, simplifyDataFrame = TRUE, flatten = TRUE)
@giocomai
giocomai / Words disappearing from SOTEU animated.R
Last active Sep 12, 2018
Words disappearing from SOTEU animated
View Words disappearing from SOTEU animated.R
# load libraries
library("gganimate")
library("tidyverse")
# introduce data
structure(list(id = c("Barroso\n2010", "Barroso\n2010", "Barroso\n2010",
"Barroso\n2011", "Barroso\n2011", "Barroso\n2011", "Barroso\n2012",
"Barroso\n2012", "Barroso\n2012", "Barroso\n2013", "Barroso\n2013",
@giocomai
giocomai / fertility_age_eurostat.Rmd
Created Aug 7, 2018
Replicate NY times birth-age gap with Eurostat data
View fertility_age_eurostat.Rmd
---
title: "Birth age gap"
author: "Giorgio Comai"
date: "7 August 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
View geofacet_italy_elections_2018.R
library("geofacet")
library("ggplot2")
library("tidyverse")
library("scales")
library("readxl")
# dati ripuliti: https://data.world/sapomnia/elezioni-2018/workspace/file?filename=Risultati%20elezioni%20camera%202018%20livello%20comunale.xlsx
# basato su: https://github.com/ondata/elezionipolitiche2018
comune <- readxl::read_excel("Risultati elezioni camera 2018 livello comunale.xlsx")
@giocomai
giocomai / Exploring Putin’s annual news conference.Rmd
Created Dec 15, 2017
Exploring Putin’s annual news conference 2017
View Exploring Putin’s annual news conference.Rmd
---
title: "Exploring Putin's annual news conference"
author: "Giorgio Comai"
date: '2017-12-15'
---
```{r setup, include=FALSE, echo=TRUE, message=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
@giocomai
giocomai / MEPsOnTwitter_rtweet.R
Last active Oct 19, 2017
Extract the full twitter history of all current members of the European Parliament with R (rtweet) #rstats
View MEPsOnTwitter_rtweet.R
if (!require("pacman")) install.packages("pacman") # for taking care of package installation/loading
pacman::p_load("tidyverse")
pacman::p_load("ROAuth")
pacman::p_load("rtweet")
# this assumes authentication has been taken care of as explained here: http://rtweet.info/articles/auth.html
# it should still work, but without access tokens the limits for API requests are much slower (it would take *a lot* longer to get all tweets)
# it is expected that this script will need to be run more than once
# interim files are automatically stored and recovered if the script is re-run
You can’t perform that action at this time.