Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 513 lines (512 sloc) 13.7 KB
print(i)
}
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
print(i)
assign(i, read_feather(i))
}
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
print(f)
print(i)
#assign(i, read_feather(i))
}
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
print(f)
print(i)
assign(i, read_feather(f))
}
?gsub
#assign(i, read_feather(f))
}
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", f)
print(nm)
?gsub
print(f)
print(i)
#assign(i, read_feather(f))
}
nm <- gsub(".feather", "", i)
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
#assign(i, read_feather(f))
}
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
assign(nm, read_feather(f))
}
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
assign(nm, read_feather(f))
}
library(feather)
tic()
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
assign(nm, read_feather(f))
}
df <- int2 %>%
left_join(i2, by = "CASE_PARTICIPANT_ID") %>%
left_join(d3, by = "CASE_PARTICIPANT_ID") %>%
left_join(gbp2, by = "CASE_PARTICIPANT_ID") %>%
left_join(s2, by = "CASE_PARTICIPANT_ID")
df2 <- df %>%
#head() %>%
to_dummy(EVENT, disp, race2, suffix = "label") %>%
bind_cols(df) %>%
replace_na(`EVENT_Indictment`:CASE_PARTICIPANT_ID, disposed.x, gbp.x,
value = 0)
outfile <- here::here("data", "dataset.feather")
write_feather(df2, outfile)
qplot(df2$event_year)
toc()
library(feather)
tic()
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
assign(nm, read_feather(f))
}
df <- intake %>%
left_join(initiation, by = "CASE_PARTICIPANT_ID") %>%
left_join(dispositions, by = "CASE_PARTICIPANT_ID") %>%
left_join(gbp, by = "CASE_PARTICIPANT_ID") %>%
left_join(sentences, by = "CASE_PARTICIPANT_ID")
df2 <- df %>%
#head() %>%
to_dummy(EVENT, disp, race2, suffix = "label") %>%
bind_cols(df) %>%
replace_na(`EVENT_Indictment`:CASE_PARTICIPANT_ID, disposed.x, gbp.x,
value = 0)
outfile <- here::here("data", "dataset.feather")
write_feather(df2, outfile)
qplot(df2$event_year)
toc()
library(feather)
tic()
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
assign(nm, read_feather(f))
}
df <- intake %>%
left_join(initiation, by = "CASE_PARTICIPANT_ID") %>%
left_join(dispositions, by = "CASE_PARTICIPANT_ID") %>%
left_join(gbp, by = "CASE_PARTICIPANT_ID") %>%
left_join(sentences, by = "CASE_PARTICIPANT_ID")
df2 <- df %>%
#head() %>%
to_dummy(EVENT, disp, race2, suffix = "label") %>%
bind_cols(df) %>%
replace_na(`EVENT_Indictment`:CASE_PARTICIPANT_ID, disposed.x, gbp.x,
value = 0)
glimpse(df2)
outfile <- here::here("data", "dataset.feather")
write_feather(df2, outfile)
qplot(df2$event_year)
toc()
library(feather)
tic()
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
assign(nm, read_feather(f))
}
df <- intake %>%
left_join(initiation, by = "CASE_PARTICIPANT_ID") %>%
left_join(dispositions, by = "CASE_PARTICIPANT_ID") %>%
left_join(gbp, by = "CASE_PARTICIPANT_ID") %>%
left_join(sentences, by = "CASE_PARTICIPANT_ID")
df2 <- df %>%
#head() %>%
to_dummy(EVENT, disp, race2, suffix = "label") %>%
bind_cols(df) %>%
replace_na(`EVENT_Indictment`:CASE_PARTICIPANT_ID, disposed.x, gbp.x,
value = 0) %>%
dplyr::select(-OFFENSE_TITLE.y, -PRIMARY_CHARGE.y, -dispose.y, -gbp.y,
-CHARGE_DISPOSITION.y, -CHARGE_DISPOSITION_REASON.y,
-JUDGE.y, -CLASS.y, -class_order.y)
glimpse(df2)
outfile <- here::here("data", "dataset.feather")
write_feather(df2, outfile)
qplot(df2$event_year)
toc()
library(feather)
tic()
dir <- here::here("data", "clean")
files <- list.files(dir)
for (i in files){
f <- here::here("data", "clean", i)
nm <- gsub(".feather", "", i)
print(nm)
?gsub
print(f)
print(i)
assign(nm, read_feather(f))
}
df <- intake %>%
left_join(initiation, by = "CASE_PARTICIPANT_ID") %>%
left_join(dispositions, by = "CASE_PARTICIPANT_ID") %>%
left_join(gbp, by = "CASE_PARTICIPANT_ID") %>%
left_join(sentences, by = "CASE_PARTICIPANT_ID")
df2 <- df %>%
#head() %>%
to_dummy(EVENT, disp, race2, suffix = "label") %>%
bind_cols(df) %>%
replace_na(`EVENT_Indictment`:CASE_PARTICIPANT_ID, disposed.x, gbp.x,
value = 0) %>%
dplyr::select(-OFFENSE_TITLE.y, -PRIMARY_CHARGE.y, -disposed.y, -gbp.y,
-CHARGE_DISPOSITION.y, -CHARGE_DISPOSITION_REASON.y,
-JUDGE.y, -CLASS.y, -class_order.y)
glimpse(df2)
outfile <- here::here("data", "dataset.feather")
write_feather(df2, outfile)
qplot(df2$event_year)
toc()
glimpse(df2)
shiny::runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
file <- here::here("data", "dataset.feather")
df <- read_feather(file)
file <- here::here("data", "dataset.feather")
df <- read_feather(file)
runApp('Output/Dashboard')
DescTools::Desc(df$EVENT)
runApp('Output/Dashboard')
runApp('Output/Dashboard')
shiny::runApp('Output/Dashboard')
p ----------------------------------------------------------------------
pkgs <- c("shinydashboard","dplyr","tidyr","here", "tidyverse",
"feather", "stringr", "DT", "scales", "leaflet", "plotly")
lapply(pkgs, require, character.only = T)
infile <- here::here("data", "dataset.feather")
df <- read_feather(infile)
df$Offense_Category <- as.character(df$Offense_Category)
## Baseline Metrics -----------------------------------------------------------
overall_n <- nrow(df)
overall_median_age <- median(df$AGE_AT_INCIDENT)
## Colors ---------------------------------------------------------------------
colors <- c(
`blue` = "#236192",
`green` = "#789D4A",
`purple` = "#45308A",
`light blue` = "#0073BC",
`kellygreen` = "#078754",
`red` = "#D52C27")
col_scheme <- function(...) {
cols <- c(...)
if (is.null(cols))
return (col_scheme)
col_scheme[cols]
}
palettes <- list(
`main` = col_scheme("blue", "green", "purple"),
`cool` = col_scheme("blue", "green"),
`hot` = col_scheme("purple", "orange", "red")
)
my_pal <- function(palette = "main", reverse = FALSE, ...) {
pal <- palettes[[palette]]
if (reverse) pal <- rev(pal)
colorRampPalette(pal, ...)
}
my_pal("cool")(10)
## Setup ----------------------------------------------------------------------
pkgs <- c("shinydashboard","dplyr","tidyr","here", "tidyverse",
"feather", "stringr", "DT", "scales", "leaflet", "plotly")
lapply(pkgs, require, character.only = T)
infile <- here::here("data", "dataset.feather")
df <- read_feather(infile)
df$Offense_Category <- as.character(df$Offense_Category)
overall_n <- nrow(df)
overall_median_age <- median(df$AGE_AT_INCIDENT)
## Colors ---------------------------------------------------------------------
colors <- c(
`blue` = "#236192",
`green` = "#789D4A",
`purple` = "#45308A",
`light blue` = "#0073BC",
`kellygreen` = "#078754",
`red` = "#D52C27")
col_scheme <- function(...) {
cols <- c(...)
if (is.null(cols))
return (col_scheme)
col_scheme[cols]
}
palettes <- list(
`main` = col_scheme("blue", "green", "purple"),
`cool` = col_scheme("blue", "green"),
`hot` = col_scheme("purple", "orange", "red")
)
col_scheme <- function(...) {
cols <- c(...)
if (is.null(colors))
return (col_scheme)
col_scheme[colors]
}
palettes <- list(
`main` = col_scheme("blue", "green", "purple"),
`cool` = col_scheme("blue", "green"),
`hot` = col_scheme("purple", "orange", "red")
)
if (is.null(cols))
col_scheme <- function(...) {
cols <- c(...)
if (is.null(cols))
return (col_scheme)
col_scheme[colors]
}
col_scheme <- function(...) {
cols <- c(...)
if (is.null(cols))
return (col_scheme)
col_scheme[colors]
}
palettes <- list(
`main` = col_scheme("blue", "green", "purple"),
`cool` = col_scheme("blue", "green"),
`hot` = col_scheme("purple", "orange", "red")
)
col_scheme <- function(...) {
cols <- c(...)
if (is.null(cols))
return (colors)
col_scheme[cols]
}
palettes <- list(
`main` = col_scheme("blue", "green", "purple"),
`cool` = col_scheme("blue", "green"),
`hot` = col_scheme("purple", "orange", "red")
)
colors[cols]
col_scheme <- function(...) {
cols <- c(...)
if (is.null(cols))
return (colors)
colors[cols]
}
palettes <- list(
`main` = col_scheme("blue", "green", "purple"),
`cool` = col_scheme("blue", "green"),
`hot` = col_scheme("purple", "orange", "red")
)
my_pal <- function(palette = "main", reverse = FALSE, ...) {
pal <- palettes[[palette]]
if (reverse) pal <- rev(pal)
colorRampPalette(pal, ...)
}
my_pal("cool")(10)
scale_color_ltcu <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
pal <- ltcu_pal(palette = palette, reverse = reverse)
if (discrete) {
discrete_scale("colour", paste0("ltcu_", palette), palette = pal, ...)
} else {
scale_color_gradientn(colours = pal(256), ...)
}
}
scale_fill_ltcu <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
pal <- ltcu_pal(palette = palette, reverse = reverse)
if (discrete) {
discrete_scale("fill", paste0("ltcu_", palette), palette = pal, ...)
} else {
scale_fill_gradientn(colours = pal(256), ...)
}
}
pal <- my_pal(palette = palette, reverse = reverse)
scale_color_ltcu <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
pal <- my_pal(palette = palette, reverse = reverse)
if (discrete) {
discrete_scale("colour", paste0("ltcu_", palette), palette = pal, ...)
} else {
scale_color_gradientn(colours = pal(256), ...)
}
}
scale_fill_ltcu <- function(palette = "main", discrete = TRUE, reverse = FALSE, ...) {
pal <- my_pal(palette = palette, reverse = reverse)
if (discrete) {
discrete_scale("fill", paste0("ltcu_", palette), palette = pal, ...)
} else {
scale_fill_gradientn(colours = pal(256), ...)
}
}
runApp('Output/Dashboard')
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants), fill = colors["blue"])+
geom_bar(stat = "identity")+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year")
colors["blue"]
p1 <- dataset_filtered() %>%
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants, fill = colors["blue"]))+
geom_bar(stat = "identity")+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year")
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants, fill = colors["blue"]))+
geom_bar(stat = "identity")+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year")
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants, color = colors["blue"]))+
geom_bar(stat = "identity")+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year")
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants), color = colors["blue"])+
geom_bar(stat = "identity")+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year")
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants))+
geom_bar(stat = "identity"), fill = colors["blue"]+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year")
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants))+
geom_bar(stat = "identity", fill = colors["blue"])+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year")
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants))+
geom_bar(stat = "identity", fill = colors["blue"])+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year") + scale_fill_ltcu()
df %>%
group_by(arrest_year) %>%
summarise(Defendants = n()) %>%
ggplot(aes(arrest_year, Defendants))+
geom_bar(stat = "identity")+#, fill = colors["blue"])+
theme_minimal()+
theme(legend.position = "none")+
scale_y_continuous()+
labs(title = "Defendants by Year",
y = "# of Defendants",
x = "Arrest Year") + scale_fill_ltcu()
runApp('Output/Dashboard')
runApp('Output/Dashboard')
runApp('Output/Dashboard')
## Setup ----------------------------------------------------------------------
pkgs <- c("shinydashboard","dplyr","tidyr","here", "tidyverse",
"feather", "stringr", "DT", "scales", "leaflet", "plotly")
lapply(pkgs, require, character.only = T)
infile <- '/home/connor/CookCo/data/dataset.feather'
df <- read_feather(infile)
shiny::runApp('/srv/shiny-server/CookCo')
runApp('/srv/shiny-server/CookCo')
summary(df$AGE_AT_INCIDENT)
runApp('/srv/shiny-server/CookCo')
runApp('/srv/shiny-server/CookCo')
runApp('/srv/shiny-server/CookCo')
You can’t perform that action at this time.