Skip to content

Instantly share code, notes, and snippets.

View gorkang's full-sized avatar

Gorka Navarrete gorkang

View GitHub Profile
@gorkang
gorkang / detect_file_encoding
Last active April 19, 2022 10:22
detect_file_encoding() function to find most likely encoding of a csv file
detect_file_encoding <- function(file_path) {
# MUCH SIMPLER, and should work most of the time
# file_path = "..."
# ENC = readr::guess_encoding(file_path, n_max = 1000)
# readr::read_csv(file_path, skip = 12, locale = locale(encoding = ENC$encoding[1]))
library(cli)
library(dplyr)
@gorkang
gorkang / happiness.R
Created January 29, 2022 11:38
happiness USA 1972-2021
# Data from: https://gssdataexplorer.norc.org/trends
# Inspiration: https://twitter.com/_cingraham/status/1487094406159110147
library(tidyverse)
library(readxl)
library(geomtextpath)
FILES = list.files(path = "~/Downloads/", pattern = "happy", full.names = TRUE)
DF_raw = map_df(FILES, read_excel, skip = 11)
library(tidyverse)
DF = tibble(country = c("a", "a", "b", "b", "b"),
value = c(1, 1.01, 2, 2.01, 2),
size_dot = c(4, 2, 1, 3, 6))
plot1 = ggplot(DF, aes(value, country, fill = country)) +
geom_point(aes(size = size_dot), shape = 21, alpha = .5, position = position_dodge2(width = .2))#position_jitterdodge(seed = 5))
plot2 = ggplot(DF, aes(value, country, fill = country)) +
library(tidyverse)
library(haven)
DF = read_sav("3312.sav") # Datos de http://www.cis.es/cis/opencm/ES/1_encuestas/estudios/ver.jsp?estudio=14551
DIC = lapply(DF, attr, which = "label") %>% as_tibble() %>% pivot_longer(1:ncol(.)) %>% rename(nombre = value)
DF_plot =
DF %>%
sjlabelled::remove_all_labels() %>%
as_tibble() %>%
@gorkang
gorkang / trump_tweets.R
Last active October 6, 2020 08:03
Trump tweets
# Using {rtweet} (https://github.com/ropensci/rtweet) to check how much Trump tweeted in the last few days
# Libraries
library(rtweet)
library(tidyverse)
# Get Twitter token
file_name <- file.path(".rtweet_token5.rds")
twitter_token = readRDS(file = file_name)
@gorkang
gorkang / MoMo_Spain.R
Created April 11, 2020 08:21
Expected and actual deaths in Spain according to MoMo
# Libraries ---------------------------------------------------------------
library(tidyverse)
library(data.table)
# Read data ---------------------------------------------------------------
# DOWNLOAD DATA FROM: https://momo.isciii.es/public/momo/dashboard/momo_dashboard.html#datos
# FROM: https://github.com/JonMinton/COVID-19
DF = tidied_data %>%
filter(type == "confirmed") %>%
mutate(
higher = case_when(
higher == "Iran (Islamic Republic of)" ~ "Iran",
higher == "Hong Kong SAR" ~ "Hong Kong",
@gorkang
gorkang / plot.R
Last active December 6, 2019 10:11
Datos sobre la situacion de Chile desde el 19 de Octubre
# Archivo PDF de:
# http://ddhh.minjusticia.gob.cl/informacion-sobre-la-situacion-del-pais-desde-el-19-de-octubre
# 2019-12-05: https://www.scribd.com/document/438470416/Datos-05-12-19#download
# Librerias -----------------------------------------------------------------------------------
library(tidyverse)
library(tabulizer)