Skip to content

Instantly share code, notes, and snippets.

View adisarid's full-sized avatar

Adi Sarid adisarid

View GitHub Profile
@adisarid
adisarid / bar_ilan_game2.R
Created February 10, 2024 21:56
solution to bar-ilan math riddle #2
"000"
"00O"
"0O0"
"0OO"
"O0O"
"OO0"
"OOO"
series_length <- 42
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 December 4, 2020 07:57
Example for making a modal with box elements and a selectInput
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"))
)
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]")
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",
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 August 3, 2020 05:50
An adaptation of a right to left cascading style sheet to be used in shinydashboards
/*******************************************************************************
* 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 July 14, 2020 13:01
Source of many frustrations when using fct_inorder
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 July 8, 2020 19:27
Distribution of symptom onset time from transmission
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 18:30
Right to left direction and alignment in ggplot2 charts
library(ggplot2)
ggplot() +
ggtitle(label = "הסימן הזה הפוך!",
subtitle = "\u202bאבל דווקא זה בסדר!") +
theme(plot.title = ggplot2::element_text(hjust = 1),
plot.subtitle = ggplot2::element_text(hjust = 1))