Skip to content

Instantly share code, notes, and snippets.

View avallecam's full-sized avatar
🎯
Focusing

Andree Valle Campos avallecam

🎯
Focusing
View GitHub Profile
@avallecam
avallecam / read_excel_multiline_reprex.R
Last active January 20, 2022 11:43
how to read a multiple line excel dataset?
fuente: https://github.com/tidyverse/readxl/issues/486#issuecomment-398224438
``` r
library(tidyverse)
library(readxl)
file_path <- "https://github.com/brianwdavis/public/raw/master/example.xlsx"
download.file(file_path, "example.xlsx", mode = "wb")
#>
read_excel_multiline <- function(filename, row_collapse = 1, ...) {
@avallecam
avallecam / regresion_mpc.R
Last active April 2, 2022 18:11
usar regresion con multiples puntos de cambio para calcular cambio en serie de tiempo
``` r
# 1 el problema! ------------------------------------------------------------
```
la base de datos inicial tiene las columnas de
anho y semana
sin embargo, para realizar un análisis de regresion
en el tiempo, las variables del tiempo tienen que
ir del 1 al infinito
es decir, no podemos hacer una regresion con
@avallecam
avallecam / ggplot2_control_axis_date_breaks.R
Last active March 18, 2022 14:56
how to control the appearance of unwanted date breaks for year-week axis
# https://community.rstudio.com/t/why-does-scale-x-date-create-labels-for-the-padded-area-too/3031
# https://gist.github.com/avallecam/b5b9738c4eede2f1008daa514aeab2ae
``` r
# 1 instalar paquetes -------------------------------------------------------
if(!require("tidyverse")) install.packages("tidyverse")
if(!require("lubridate")) install.packages("lubridate")
if(!require("outbreaks")) install.packages("outbreaks")
if(!require("aweek")) install.packages("aweek")
@avallecam
avallecam / ggplot2_dualaxis_integerbreaks.R
Last active August 29, 2021 18:23
add a second axis and integer breaks on a ggplot2
# adaptacion de: https://www.r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html
# uso de solucion: https://stackoverflow.com/a/27495865/6702544
``` r
# Libraries
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.0.4
#> Warning: package 'tibble' was built under R version 4.0.5
#> Warning: package 'dplyr' was built under R version 4.0.5
@avallecam
avallecam / anonymize_tibble.R
Last active July 9, 2021 21:22
use epitrix::hash_names() inside tibble
# fuente: https://www.repidemicsconsortium.org/epitrix/\#anonymising-data
# en bases con 3000 observaciones puede demorar ~95 segundos
``` r
if(!require("tidyverse")) install.packages("tidyverse")
if(!require("charlatan")) install.packages("charlatan")
if(!require("epitrix")) install.packages("epitrix")
library(tidyverse)
library(charlatan)
@avallecam
avallecam / ggsave_reprex.R
Last active June 30, 2021 16:25
usar ggsave dpi retina para grabar imágenes en alta resolución
``` r
# instalar paquetes
if(!require("tidyverse")) install.packages("tidyverse")
if(!require("palmerpenguins")) install.packages("palmerpenguins")
# llamar paquete
library(tidyverse)
# importar y limpiar datos
pinguinos <- palmerpenguins::penguins %>%
@avallecam
avallecam / str_replace_regex.R
Last active June 25, 2021 19:15
using regex inside str_replace()
``` r
library(tidyverse)
tibble(variable="nombre (apellido compuesto)") %>%
#' expresiones regulares
#' caso 1:
#' nombre (apellido)
#' .+ .+
#' (.+) (.+)
#' \\1 \\2
#'
@avallecam
avallecam / geom_tile_heatmap.R
Last active March 27, 2021 01:03
create heatmap with geom_tile
``` r
# reprex from: https://github.com/avallecam/epichannel
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.0.4
# disease dataset
denv <-
readr::read_csv("https://dengueforecasting.noaa.gov/Training/Iquitos_Training_Data.csv") %>%
@avallecam
avallecam / survey_srvy_syntax.R
Last active August 24, 2020 22:15
examples with srvyr syntaxs. WARNING when proportion = TRUE
``` r
# packages ----------------------------------------------------------------
library(tidyverse)
library(srvyr)
library(survey)
# data --------------------------------------------------------------------
@avallecam
avallecam / incidence_block_ggplot.R
Created August 9, 2020 00:55
sometimes required brick like bar or histogram plots
``` r
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 3.6.3
#> Warning: package 'dplyr' was built under R version 3.6.3
#> Warning: package 'forcats' was built under R version 3.6.3
library(outbreaks)
fluH7N9_china_2013 %>%
as_tibble() %>%
ggplot(aes(x = date_of_onset)) +
geom_bar() +