Skip to content

Commit

Permalink
Add, style, and roxygenise functions
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyokc committed Oct 1, 2023
1 parent 14a3714 commit 2acec48
Show file tree
Hide file tree
Showing 40 changed files with 5,001 additions and 564 deletions.
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
104 changes: 100 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,102 @@
# Generated by roxygen2: do not edit by hand

export(hello)
export(plumber_api)
export(shiny_app)
importFrom(utils,packageName)
export(covid_eviction_labels)
export(custom_ojo_theme)
export(hc_theme_ojo)
export(highchart_label_formatter)
export(ojo_add_geoid)
export(ojo_add_geometries)
export(ojo_add_month_and_year)
export(ojo_add_population)
export(ojo_aggregate)
export(ojo_district_and_date_filters)
export(ojo_highchart_map)
export(ojo_optional_filter)
export(ojo_plot_lines)
export(pretty_variable_names)
export(tably)
importFrom(dplyr,any_of)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
importFrom(dplyr,count)
importFrom(dplyr,cross_join)
importFrom(dplyr,distinct)
importFrom(dplyr,filter)
importFrom(dplyr,if_else)
importFrom(dplyr,join_by)
importFrom(dplyr,left_join)
importFrom(dplyr,matches)
importFrom(dplyr,mutate)
importFrom(dplyr,nth)
importFrom(dplyr,pull)
importFrom(dplyr,select)
importFrom(dplyr,slice)
importFrom(dplyr,starts_with)
importFrom(dplyr,summarise)
importFrom(dplyr,tibble)
importFrom(geojsonsf,sf_geojson)
importFrom(ggplot2,aes)
importFrom(ggplot2,annotate)
importFrom(ggplot2,as_labeller)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,element_text)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,geom_label)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_rect)
importFrom(ggplot2,geom_vline)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,guide_legend)
importFrom(ggplot2,guides)
importFrom(ggplot2,scale_color_manual)
importFrom(ggplot2,scale_fill_manual)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,vars)
importFrom(grDevices,nclass.FD)
importFrom(graphics,hist)
importFrom(highcharter,color_classes)
importFrom(highcharter,color_stops)
importFrom(highcharter,hc_add_series_map)
importFrom(highcharter,hc_add_theme)
importFrom(highcharter,hc_caption)
importFrom(highcharter,hc_colorAxis)
importFrom(highcharter,hc_legend)
importFrom(highcharter,hc_mapNavigation)
importFrom(highcharter,hc_theme)
importFrom(highcharter,hc_theme_merge)
importFrom(highcharter,hc_theme_smpl)
importFrom(highcharter,highchart)
importFrom(htmlwidgets,JS)
importFrom(jsonlite,fromJSON)
importFrom(lubridate,floor_date)
importFrom(lubridate,year)
importFrom(lubridate,ymd)
importFrom(ojodb,ojo_pal)
importFrom(purrr,map_chr)
importFrom(rlang,as_label)
importFrom(rlang,check_installed)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,quo_get_expr)
importFrom(rlang,quo_text)
importFrom(rlang,quos)
importFrom(rlang,sym)
importFrom(scales,label_comma)
importFrom(snakecase,to_title_case)
importFrom(stats,filter)
importFrom(stats,na.omit)
importFrom(stringr,str_detect)
importFrom(stringr,str_flatten)
importFrom(stringr,str_remove)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_to_upper)
importFrom(tidycensus,get_estimates)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(tigris,counties)
importFrom(tigris,states)
importFrom(viridis,magma)
80 changes: 50 additions & 30 deletions R/covid_eviction_labels.R
Original file line number Diff line number Diff line change
@@ -1,100 +1,120 @@
#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' @param label_data PARAM_DESCRIPTION
#' @param ... PARAM_DESCRIPTION
#' @param .labels PARAM_DESCRIPTION, Default: FALSE
#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples
#' \dontrun{
#' if(interactive()){
#' #EXAMPLE1
#' }
#' }
#' @seealso
#' \code{\link[ggplot2]{geom_label}}, \code{\link[ggplot2]{aes}}, \code{\link[ggplot2]{annotate}}, \code{\link[ggplot2]{geom_raster}}, \code{\link[ggplot2]{scale_manual}}, \code{\link[ggplot2]{guide_legend}}, \code{\link[ggplot2]{geom_abline}}
#' \code{\link[lubridate]{ymd}}
#' @rdname covid_eviction_labels
#' @export
#' @author Anthony Flores
#' @importFrom ggplot2 geom_label aes annotate geom_rect scale_fill_manual guide_legend geom_vline
#' @importFrom lubridate ymd
covid_eviction_labels <- function(label_data, ..., .labels = FALSE) {

ojo_labels <- function(.label, data = label_data, .x, .y) {
"Helper: Makes it more efficient to make and edit the aesthetics of all labels at once."
geom_label(
ggplot2::geom_label(
data = data,
label = .label,
aes(x = {{.x}}, y = {{.y}}, group = variable),
ggplot2::aes(x = {{ .x }}, y = {{ .y }}, group = variable),
fontface = "bold", size = 2.5, hjust = -0.02,
label.size = 0, fill = "#dddddd", color = "#231f20"
)
)
}

# Dates of events are rounded to nearest month for readability
# COVID State of Emergency Declared
date_covid <- ymd("2020-03-01")
date_covid <- lubridate::ymd("2020-03-01")
# Federal Eviction Moratorium Begins (CARES Act passed 3-24-2020)
date_federalMoratoriumBegins <- ymd("2020-04-01")
date_federalMoratoriumBegins <- lubridate::ymd("2020-04-01")
# Federal Eviction Moratorium Expires 7/25/2020
date_federalMoratoriumExpires <- ymd("2020-08-01")
date_federalMoratoriumExpires <- lubridate::ymd("2020-08-01")
# CDC Moratorium Begins 9/4/2020
date_cdcMoratoriumBegins <- ymd("2020-09-01")
date_cdcMoratoriumBegins <- lubridate::ymd("2020-09-01")
# CDC Moratorium Expires 7/31/2021
date_cdcMoratoriumEnds <- ymd("2021-08-01")
date_cdcMoratoriumEnds <- lubridate::ymd("2021-08-01")


components <- list(
# Highlight dates where there is an active eviction moratorium or court closure.
annotate(
ggplot2::annotate(
"rect",
xmin = date_covid, xmax = date_federalMoratoriumExpires,
ymin = -Inf, ymax = Inf,
xmin = date_covid, xmax = date_federalMoratoriumExpires,
ymin = -Inf, ymax = Inf,
fill = "#000000", alpha = 0.25,
color = NA
),
annotate(
ggplot2::annotate(
"rect",
xmin = date_cdcMoratoriumBegins, xmax = date_cdcMoratoriumEnds,
ymin = -Inf, ymax = Inf,
xmin = date_cdcMoratoriumBegins, xmax = date_cdcMoratoriumEnds,
ymin = -Inf, ymax = Inf,
fill = "#000000", alpha = 0.25,
color = NA
),
# We use this to make the legend (the x & y values don't matter)
geom_rect(
aes(
ggplot2::geom_rect(
ggplot2::aes(
xmin = date_covid, xmax = date_federalMoratoriumBegins,
ymin = 0, ymax = Inf,
fill = "Active Eviction Moratorium\nor Court Closure",
color = NULL
)
),
scale_fill_manual(
ggplot2::scale_fill_manual(
name = "",
values = c("Active Eviction Moratorium\nor Court Closure" = "#00000000"),
guide = guide_legend(override.aes = list(fill = "#000000", alpha = .2))
guide = ggplot2::guide_legend(override.aes = list(fill = "#000000", alpha = .2))
)
)


if (.labels == TRUE) {
components <- append(components, list(
geom_vline(xintercept = date_covid, linetype = "dashed"),
geom_vline(xintercept = date_federalMoratoriumBegins, linetype = "dashed"),
geom_vline(xintercept = date_federalMoratoriumExpires, linetype = "dashed"),
geom_vline(xintercept = date_cdcMoratoriumBegins, linetype = "dashed"),
geom_vline(xintercept = date_cdcMoratoriumEnds, linetype = "dashed"),
ggplot2::geom_vline(xintercept = date_covid, linetype = "dashed"),
ggplot2::geom_vline(xintercept = date_federalMoratoriumBegins, linetype = "dashed"),
ggplot2::geom_vline(xintercept = date_federalMoratoriumExpires, linetype = "dashed"),
ggplot2::geom_vline(xintercept = date_cdcMoratoriumBegins, linetype = "dashed"),
ggplot2::geom_vline(xintercept = date_cdcMoratoriumEnds, linetype = "dashed"),
ojo_labels(
data = label_data,
.label = "COVID State of Emergency:\nCourt Closes Temporarily",
.x = date_covid,
.y = maxValue * .95
),
),
ojo_labels(
data = label_data,
.label = "CARES Act: Federal Eviction Moratorium Issued",
.x = date_federalMoratoriumBegins,
.y = maxValue * .8
),
),
ojo_labels(
data = label_data,
.label = "Federal Eviction\nMoratorium Expires",
.x = date_federalMoratoriumExpires,
.y = maxValue * .7
),
),
ojo_labels(
data = label_data,
.label = "CDC Eviction\nMoratorium Issued",
.x = date_cdcMoratoriumBegins,
.y = maxValue * .2
),
),
ojo_labels(
data = label_data,
.label = "CDC Eviction\nMoratorium Expires",
.x = date_cdcMoratoriumEnds,
.y = maxValue * .95
)
))
)
))
}


Expand Down
45 changes: 31 additions & 14 deletions R/custom_ojo_theme.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION

#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples
#' \dontrun{
#' if(interactive()){
#' #EXAMPLE1
#' }
#' }
#' @seealso
#' \code{\link[ggplot2]{ggtheme}}, \code{\link[ggplot2]{theme}}, \code{\link[ggplot2]{margin}}
#' @rdname custom_ojo_theme
#' @export
#' @author Anthony Flores
#' @importFrom ggplot2 theme_bw theme element_blank element_rect element_text
custom_ojo_theme <- function() {
ggplot2::theme_bw(
base_size = 16,
base_family = "roboto_condensed"
) %+replace%
ggplot2::theme(
panel.background = ggplot2::element_blank(),
plot.background = ggplot2::element_blank(),
legend.background = ggplot2::element_rect(fill = "transparent", colour = NA),
legend.key = ggplot2::element_rect(fill = "transparent", colour = NA),
legend.position = "top"
) +
theme(
legend.title = element_blank(),
legend.text = element_text(size = 14),
axis.title = element_blank(),
strip.background = element_blank(),
strip.text = element_text(face = "bold")
)
ggplot2::theme(
panel.background = ggplot2::element_blank(),
plot.background = ggplot2::element_blank(),
legend.background = ggplot2::element_rect(fill = "transparent", colour = NA),
legend.key = ggplot2::element_rect(fill = "transparent", colour = NA),
legend.position = "top"
) +
ggplot2::theme(
legend.title = ggplot2::element_blank(),
legend.text = ggplot2::element_text(size = 14),
axis.title = ggplot2::element_blank(),
strip.background = ggplot2::element_blank(),
strip.text = ggplot2::element_text(face = "bold")
)
}
57 changes: 39 additions & 18 deletions R/hc_theme_ojo.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
library(highcharter)
library(ojodb)
hc_theme_ojo <- hc_theme_merge(
hc_theme_smpl(),
hc_theme(
colors = ojo_pal,
plotOptions = list(
line = list(
lineWidth = 3,
marker = list(
enabled = TRUE,
lineColor = "#000000",
lineWidth = 1.5
#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION

#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples
#' \dontrun{
#' if(interactive()){
#' #EXAMPLE1
#' }
#' }
#' @seealso
#' \code{\link[highcharter]{hc_theme_merge}}, \code{\link[highcharter]{hc_theme_smpl}}, \code{\link[highcharter]{hc_theme}}
#' \code{\link[ojodb]{ojo_pal}}
#' @rdname hc_theme_ojo
#' @export
#' @author Anthony Flores
#' @importFrom highcharter hc_theme_merge hc_theme_smpl hc_theme
#' @importFrom ojodb ojo_pal
hc_theme_ojo <- function() {
theme <- highcharter::hc_theme_merge(
highcharter::hc_theme_smpl(),
highcharter::hc_theme(
colors = ojodb::ojo_pal,
plotOptions = list(
line = list(
lineWidth = 3,
marker = list(
enabled = TRUE,
lineColor = "#000000",
lineWidth = 1.5
)
)
),
legend = list(
align = "center",
verticalAlign = "top"
)
),
legend = list(
align = "center",
verticalAlign = "top"
)
)
)

return(theme)
}
Loading

0 comments on commit 2acec48

Please sign in to comment.