Skip to content

Instantly share code, notes, and snippets.

View RamiKrispin's full-sized avatar
👻
Focusing

Rami Krispin RamiKrispin

👻
Focusing
View GitHub Profile
@RamiKrispin
RamiKrispin / gist:c61dc3fb7cc01e8985a2de5e129cab69
Last active September 9, 2019 15:30
Terminal common commands

Notes about command lines functions from the "Data Science at the Command Line"

echo is a command that outputs the strings it is being passed as arguments

echo 'Hello World'
Hello World
@RamiKrispin
RamiKrispin / coronavirus_new_cases.R
Created February 23, 2020 21:17
Coronavirus daily new cases dist. China vs. rest of the world plot
#----------------------------------------
# Plotting the daily new confirmed cases
# China vs. rest of the world
#----------------------------------------
# Data: coronavirus dataset from the coronavirus package
# Using github version as it update the data on daily bases
#----------------------------------------
# Installing most recent version from Github
# must reset the R session after installation
# install.packages("devtools")
`%>%` <- magrittr::`%>%`
dates_seq <- seq.Date(from = as.Date("2018-11-24"), to = as.Date("2018-11-30"), by = "day")
df <- lapply(dates_seq, function(i){
cmd <- paste("curl -X GET https://api.carbonintensity.org.uk/intensity/", i,
"T00:00Z/", i,
"T23:30Z | jq --raw-output '.data[] | [.from, .intensity.actual] | @tsv'",
sep = "")
@RamiKrispin
RamiKrispin / coronavirus_bar_filter.R
Created February 28, 2020 14:57
Creating bar chart with filter
library(coronavirus)
df <- coronavirus %>%
# dplyr::filter(date == max(date)) %>%
dplyr::group_by(Country.Region, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(names_from = type,
values_from = total) %>%
dplyr::arrange(-confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = factor(Country.Region, levels = Country.Region))
@RamiKrispin
RamiKrispin / China_province_dist.R
Created February 29, 2020 16:48
Creating dist plot for China province
province_vec <- coronavirus %>%
dplyr::filter(type == "confirmed", Country.Region == "Mainland China") %>%
dplyr::group_by(Province.State) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
dplyr::arrange(-total) %>%
dplyr::select(province = Province.State)
coronavirus %>%
dplyr::filter(type == "confirmed", Country.Region == "Mainland China") %>%
@RamiKrispin
RamiKrispin / coronavirus_daily_by_type.R
Created March 2, 2020 16:50
Coronavirus daily cumulative cases by type
#---------------- Plotting Daily Cumulative Cases of the Coronavirus----------------
# Installing the most update version of the coronavirus
# install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")
data("coronavirus")
# Reformat and aggregate the data to daily by country and type of case
df_daily <- coronavirus %>%
dplyr::group_by(date, type) %>%
@RamiKrispin
RamiKrispin / coronavirus_italy_sk_example.R
Created March 11, 2020 17:08
Loading Italy and South Korea coronavirus dataset
# Install the Github version (refreshed on a daily bases):
# install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")
library(coronavirus)
data("covid_italy")
head(covid_italy)
# Creating a tree-map plot for the total covid19 confirmed cases in Italy
#------------------------------------------------------------------------
# Required packages
library(covid19italy)
library(dplyr)
library(plotly)
# Check for updates
update_data()
library(plotly)
data(mtcars)
plot_ly(data = mtcars, x = ~ hp, y = ~ mpg)
plot_ly(x = ~ mtcars[,"hp"], y = mtcars[, "mpg"])
var1 <- "hp"
var2 <- "mpg"
#---------------------------------------------------------
# Creating a trajectory plot for covid19 confirmed cases
# Required packages - dplyr, tidyr, and plotly packages
# Data - coronavirus package
#---------------------------------------------------------
# To get the most update data use the Github version
#devtools::install_github("RamiKrispin/coronavirus")
library(coronavirus)
`%>%` <- magrittr::`%>%`