Skip to content

Instantly share code, notes, and snippets.

View gonzalezgouveia's full-sized avatar

Rafael Gonzalez Gouveia gonzalezgouveia

View GitHub Profile
# animando
anim %>% animate(fps = 30,
nframes = 300,
detail = 10,
start_pause = 30,
end_pause = 30,
rewind = FALSE,
width = 400,
height = 400)
# crear animación
anim <- p +
# animacion con cambios en los estados del año
transition_states(year,
transition_length = 1,
state_length = 0,
wrap = FALSE) +
# permitir que los ejes cambien
view_follow()
# hacer objeto de grafica
p <- population_tidy %>%
ggplot(aes(ordering, group = country)) +
# utilizar geom_tile en lugar de geom_bar
geom_tile(aes(y = population10/2,
height = population10,
width = 0.9, fill=country), alpha = 0.9) +
# texto en las barras
geom_text(aes(y = population10, label = paste(as.character(round(population10)), 'M')),
vjust = 0.4, hjust = 0.55, size = 7) +
# crear datos tidy u ordenados
population_tidy <- population_data%>%
# filtrar para algunos paises de HispanoAmérica
filter(country %in% c('Argentina',
'Chile',
'Colombia',
'Ecuador',
'Mexico',
'Panama',
'Peru',
# descargar datos en https://www.gapminder.org/data/
# escribir la ruta de los datos
path_to_data <- './population_total.csv'
# leer archivo csv
population_data <- read_csv(path_to_data)
library(tidyverse)
library(gganimate)
# devtools::install_github('bbc/bbplot')
library(bbplot)
library(ggthemes)
# Hecho por Rafa @GonzalezGouveia
# Con gusto para #DatosDeMiercoles, propuesto por @R4DS_es
cambio_lealtades <- readr::read_csv("https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-04-17/cambio_lealtades.csv")
# tiempo_pantalla <- readr::read_csv("https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-04-17/tiempo_pantalla.csv")
library(tidyverse)
library(ggthemes)
# Por Rafa @GonzalezGouvia
# leyendo directo de la página
partidos_fifa_copa_mundial_procesado <- readr::read_delim("https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-04-10/partidos.txt", delim = "\t")
# función auxiliar para extraer ultimo partido
quita_parentesis <- function(texto){
as.integer(gsub("\\((.*)\\)", "\\1", texto))
library(tidyverse)
# datos
# survey1: Cuál es el mayor uso que le das a R en tus análisis?
survey1 <- tibble(
# preguntas
option = c(
"Modelos",
"Gráficos",
def select_name(gender):
'''select a name based on gender'''
if gender == 'M':
name = np.random.choice(name_men_list)
elif gender == 'F':
name = np.random.choice(name_women_list)
return(name.split(' ')[0].capitalize())
def create_table(n):
# set simulation parameters
low_age = 18
high_age = 60
low_height = 1.5
high_height = 2
decimals = 2
genders = ['M', 'F']