Skip to content

Instantly share code, notes, and snippets.

Avatar

Adi Sarid adisarid

View GitHub Profile
View poor_vs_religiosness_religion.R
library(tidyverse)
library(patchwork)
library(glue)
tib <-
tribble(~sector, ~poor_overall, ~population_portion, ~poor_percent,
"secular", 0.27, 0.66, 0.086,
"ultra-orthodox", 0.26, 0.11, 0.52,
"arab", 0.454, 0.2, 0.47,
"others", 0.016, 0.03, 0.113) %>%
@adisarid
adisarid / app.R
Created Dec 4, 2020
Example for making a modal with box elements and a selectInput
View app.R
library(shiny)
library(shinydashboard)
# Define UI for application that draws a histogram
ui <- dashboardPage(title = "Simple dashboard",
header = dashboardHeader(),
sidebar = dashboardSidebar(),
dashboardBody(actionButton("open_modal", "Open modal"),
textOutput("chosen_fruit"))
)
View wind_turbines_in_canada.R
library(tidyverse)
wind_turbine <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-10-27/wind-turbine.csv')
p1 <- ggplot(wind_turbine, aes(x = rotor_diameter_m, y = turbine_rated_capacity_k_w)) +
geom_point() +
stat_smooth(method = "lm") +
ggtitle("Capacity vs rotor diameter") +
ylab("Capacity [kW]") +
xlab("Rotor diameter [m]")
View samsung_smartwatch_issues.R
watch_levels <- tribble(~time, ~battery, ~status,
"2020-08-19 18:27", 0.94, "actual",
"2020-08-19 18:27", 0.94, "predicted",
"2020-08-19 22:42", 0.57, "actual",
"2020-08-20 06:42", 0, "actual") %>%
mutate(time = as.POSIXct(time)) %>%
bind_rows(tibble(time = as.POSIXct("2020-08-19 18:27") + (24+5)*60*60 + 120,
battery = 0,
status = "predicted")) %>%
mutate(status = case_when(status == "actual" ~ "What actually happened",
View example_for_geom_segment.R
example1 <- tribble(~x, ~y, ~x_end, ~y_end,
0, 0, 1, 1,
1.5, 1, 2, 2,
3, 5, 4, 2)
example_pointed <- example1 %>% select(x,y) %>%
bind_rows(example1 %>% select(x_end, y_end) %>% set_names(c("x", "y")))
ggplot(example1, aes(x = x, y = y)) +
geom_segment(aes(x = x, y = y, xend = x_end, yend = y_end), lineend = "round") +
@adisarid
adisarid / bootstrap-rtl.css
Created Aug 3, 2020
An adaptation of a right to left cascading style sheet to be used in shinydashboards
View bootstrap-rtl.css
/*******************************************************************************
* bootstrap-rtl (version 3.3.4)
* Author: Morteza Ansarinia (http://github.com/morteza)
* Created on: August 13,2015
* Project: bootstrap-rtl
* Copyright: Unlicensed Public Domain
*******************************************************************************/
/*
Work to allow handsontable to go from right to left
@adisarid
adisarid / example_fct_inorder_frustrations.R
Created Jul 14, 2020
Source of many frustrations when using fct_inorder
View example_fct_inorder_frustrations.R
library(tidyverse)
example1 <- tibble(size = c("A", "A", "C", "C", "B", "B"),
re_order_var = c(1,1,2,2,3,3))
# works as expected:
example1 %>%
arrange(re_order_var) %>%
mutate(size = fct_inorder(size)) %>%
ggplot(aes(size, y = 1)) +
@adisarid
adisarid / symptoms_onset_distribution.R
Created Jul 8, 2020
Distribution of symptom onset time from transmission
View symptoms_onset_distribution.R
tibble(plnorm = 0.8*plnorm(q = seq(0, 20, by = 0.1), meanlog = 1.621, sdlog = 0.418),
q = seq(0, 20, by = 0.1)) %>%
ggplot(aes(x = q, y = plnorm)) +
geom_point() +
coord_cartesian(ylim = c(0,1))
# https://www.eurosurveillance.org/content/10.2807/1560-7917.ES.2020.25.10.2000180#html_fulltext
# https://www.acpjournals.org/doi/10.7326/M20-0504
@adisarid
adisarid / rtl_ggplot.R
Created May 7, 2020
Right to left direction and alignment in ggplot2 charts
View rtl_ggplot.R
library(ggplot2)
ggplot() +
ggtitle(label = "הסימן הזה הפוך!",
subtitle = "\u202bאבל דווקא זה בסדר!") +
theme(plot.title = ggplot2::element_text(hjust = 1),
plot.subtitle = ggplot2::element_text(hjust = 1))
@adisarid
adisarid / nifgaim_year.csv
Last active Apr 27, 2020
סטטיסטיקה על חללים ונפגעי פעולות איבה 1947-2019
View nifgaim_year.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
חללים פעולות_איבה שנה
197 3 1947
4416 118 1948
295 4 1949
131 6 1950
185 10 1951
145 4 1952
149 15 1953
144 6 1954
141 1 1955