This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ggrepel) | |
ny_sh <- read.csv("data/NYPD_Shooting_Incident_Data__Historic_.csv") | |
ny_sh_prep <- ny_sh %>% | |
mutate(date = mdy(OCCUR_DATE), | |
year = year(date), | |
month = month(date, | |
label = T, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Quick fix for stargazer <= 5.2.3 is.na() issue with long model names in R >= 4.2 | |
# Unload stargazer if loaded | |
detach("package:stargazer",unload=T) | |
# Delete it | |
remove.packages("stargazer") | |
# Download the source | |
download.file("https://cran.r-project.org/src/contrib/stargazer_5.2.3.tar.gz", destfile = "stargazer_5.2.3.tar.gz") | |
# Unpack | |
untar("stargazer_5.2.3.tar.gz") | |
# Read the sourcefile with .inside.bracket fun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
link <- "https://ege.hse.ru/rating/2018/75767740/all/" | |
tab <- read_html(link) %>% | |
# Detect everything that looks like a table | |
html_table() %>% | |
# Choose second element in the list (rvest found two tables) | |
.[[2]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(lubridate) | |
library(dplyr) | |
library(ggmap) | |
# Data: https://www.opendataphilly.org/dataset/crime-incidents | |
philly <- fread("data/incidents.csv", | |
select = c("location_block","text_general_code","dispatch_time","dispatch_date", "lat","lng")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(lubridate) | |
library(dplyr) | |
library(ggmap) | |
library(stargazer) | |
# Data: https://www.opendataphilly.org/dataset/crime-incidents | |
philly <- fread("incidents.csv", | |
select = c("location_block","text_general_code","dispatch_time","dispatch_date", "lat","lng")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages(c("readxl","rio","dplyr","ggplot2")) | |
library(dplyr) | |
library(ggplot2) | |
rio::import("http://www.gks.ru/free_doc/2017/demo/t3_3.xls") %>% | |
slice(-c(1:7, 9:11, 13, 14, 17, 21:23, 27, 29, 38)) %>% | |
select(1:2) %>% | |
setNames(c("cause","number")) %>% | |
mutate(cause = gsub("из них от|в том числе от|1)|\\:", "", cause), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(ggvis) | |
# Load data | |
df <- read.csv("data/murder_crimes_by_regions.csv", stringsAsFactors = F) | |
# Define UI | |
ui <- fluidPage( | |
titlePanel("Убийства в России"), | |
div( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(ggvis) | |
df <- read.csv("https://github.com/alexeyknorre/workshop_undone_2018/raw/master/murder_crimes_by_regions.csv", | |
encoding = "CP1251", | |
stringsAsFactors = F) | |
shinyServer(function(input, output) { | |
region_popup <- function(x) { |