Skip to content
View Guibi1994's full-sized avatar
🏠
Working from home
🏠
Working from home

Block or report Guibi1994

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
Guibi1994/README.md

Fast notes :)

GCP query

a0_base <- bq_table_download(bq_project_query(
"project", 
` ("SQL quary")))  `

boxplot mean poitns

p <- p + stat_summary(fun.y = mean, geom = "point",
               shape = 20, size = 4, color = "turquoise") 

Save plots in googledrive

ggdrive_save <- function(
    plot,
    drive_location,
    name,w =5,h=5) {
  # Description: This funtion exports an image to drive
  
  # a. Local saving
  ggplot2::ggsave(
    plot = plot,
    filename = name,
    width = w,
    height = h)
  # b. Drive saving
  googledrive::drive_upload(
    media = name,
    path = paste0(drive_location,"/",name),
    overwrite = T)
  # c. Removign local file
  file.remove(name)
}

Fast Barplots

univar_plot <- function(data,variable) {
  ncolors = data %>%
    summarise(ncolors = n_distinct({{variable}})) %>%
    pull(ncolors)
  
  data %>% 
    group_by({{variable}}) %>% 
    summarise(n = n()) %>%
    mutate(tot= sum(n),
           pp = 100*round(n/tot,3),
           my_label = paste0(n, " (",pp,"%)"),
           text_color = ifelse(pp>1.5,"white","grey20"),
           text_position = ifelse(pp>1.5,(n/2),quantile(n,probs = 0.3)),
           text_angle = ifelse(pp>10,0,270)) %>% 
    # Plot
    ggplot(aes(n, {{variable}},
               group = {{variable}},
               fill = {{variable}})) +
    scale_fill_manual(values = c(my_colors[1:ncolors]))+
    geom_bar(stat = "identity", alpha = .8)+
    geom_text(aes(text_position,{{variable}}, label = my_label,
                  family = "serif",color = text_color, 
                  angle = text_angle),size = 3)+
    scale_color_identity()+
    #Theme
    my_theme
}
bivar_plot <- function(data, var1,var2) {
  data %>% 
    group_by({{var1}}, {{var2}}) %>% 
    summarise(n = n()) %>% 
    arrange(desc({{var2}})) %>% 
    group_by({{var1}}) %>% 
    mutate(tot = sum(n),
           pp = round(n/tot,3),
           text_position = ((cumsum(pp))-pp)+(pp/2),
           my_label = paste0(n, "  (",100*pp,"%)"),
           text_color = ifelse(pp>.02,"white","grey"),
           text_angle = ifelse(pp>.1,0,-90)) %>% 
    # Plot
    ggplot(aes(pp,{{var1}},fill = {{var2}}))+
    geom_bar(stat = "identity")+
    scale_fill_manual(values = c(my_colors))+
    geom_text(aes(text_position,{{var1}}, label = my_label,
                  family = "serif", color = text_color, angle = text_angle),
              size = 3)+
    scale_color_identity()+
    my_theme2
}

Pinned Loading

  1. Neighborhood_Legalization Neighborhood_Legalization Public

    Neighborhood Legalization

    R

  2. Los-incuestionables Los-incuestionables Public

    Análisis de las declaraciones de renta de los congresistas en Colombia

    R

  3. Twits_and_posts Twits_and_posts Public

    R

  4. Vulnerability-knowledge-and-enforcement-of-labor-rights-in-the-domestic-workforce Vulnerability-knowledge-and-enforcement-of-labor-rights-in-the-domestic-workforce Public

    Vulnerability, knowledge, and enforcement of labor rights in the domestic workforce. . A study case in Bogotá, Colombia

    R