-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from CMAP-REPOS/version1.2
Version1.2
- Loading branch information
Showing
41 changed files
with
1,462 additions
and
862 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
# Automatically rebuilds pkgdown website any time master branch is updated. | ||
# Also builds pkgdown on "gh-pages-test" on commits to pull requests. | ||
# Based on <https://github.com/r-lib/actions/blob/master/examples/pkgdown.yaml>. | ||
# Conditional based on <https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables>. | ||
on: | ||
push: | ||
branches: master | ||
pull_request: | ||
|
||
name: pkgdown | ||
|
||
|
@@ -56,18 +59,32 @@ jobs: | |
install.packages("pkgdown") | ||
shell: Rscript {0} | ||
|
||
- name: Check Whitney availability | ||
- name: Check Whitney availability in R | ||
run: | | ||
message(paste(sysfonts::font_paths(), collapse = "\n")) | ||
all_fonts <- sysfonts::font_files() | ||
message(paste(all_fonts[all_fonts$family %in% c("Whitney Medium", "Whitney Book", "Whitney Semibold") & all_fonts$face=="Regular", "file"], collapse = "\n")) | ||
all_fonts <- systemfonts::system_fonts() | ||
message("WHITNEY FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") | ||
message(paste(all_fonts$name[grepl("^Whitney", all_fonts$name)], collapse = "\n")) | ||
user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") | ||
library_fonts <- list.files(user_dir) | ||
message(paste0("WHITNEY FONTS IN ", user_dir, " (MUST BE REGISTERED):")) | ||
message(paste(library_fonts[grepl("^Whitney", library_fonts)], collapse = "\n")) | ||
shell: Rscript {0} | ||
|
||
- name: Install package | ||
run: R CMD INSTALL . | ||
|
||
- name: Deploy package | ||
- name: Deploy package to live branch | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
run: | | ||
echo "This is $GITHUB_REF. Deploying to gh-pages branch." | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Actions" | ||
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, clean = TRUE)' | ||
Rscript -e 'pkgdown::deploy_to_branch(clean = TRUE)' | ||
- name: Deploy package to test branch | ||
if: ${{ github.ref != 'refs/heads/main' }} | ||
run: | | ||
echo "This is $GITHUB_REF. Deploying to gh-pages-test branch." | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Actions" | ||
Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", clean = TRUE)' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: cmapplot | ||
Title: CMAP Themes and Color Palettes | ||
Version: 1.1.0 | ||
Version: 1.2.0 | ||
Authors@R: c( | ||
person("Matthew", "Stern", | ||
role = c("aut", "cre"), | ||
|
@@ -24,7 +24,7 @@ Authors@R: c( | |
role = "aut", | ||
email = "[email protected]"), | ||
person("Chicago Metropolitan Agency for Planning", | ||
role = "cph")) | ||
role = c("cph", "fnd"))) | ||
Description: Provides themes and color scales for 'ggplot2', based on Chicago | ||
Metropolitan Agency for Planning (CMAP) design guidelines. | ||
URL: https://cmap-repos.github.io/cmapplot, https://github.com/CMAP-REPOS/cmapplot | ||
|
@@ -45,20 +45,20 @@ Imports: | |
grid, | ||
gridExtra, | ||
gridtext, | ||
lubridate, | ||
magrittr, | ||
purrr, | ||
ragg, | ||
rlang, | ||
rstudioapi, | ||
scales, | ||
stringr, | ||
sysfonts | ||
systemfonts, | ||
tibble | ||
Suggests: | ||
knitr, | ||
lubridate, | ||
readxl, | ||
RCurl, | ||
rmarkdown, | ||
testthat, | ||
tibble, | ||
tidyverse | ||
RoxygenNote: 7.1.1 | ||
VignetteBuilder: knitr |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#'Axis handling helper functions | ||
#' | ||
#'`abbr_years()` is a helper functions that allows users to abbreviate year | ||
#'labels to their two-digit representation (e.g., 2008 to '08), but not | ||
#'abbreviate any specified breaks. It does so by creating a new function that | ||
#'takes the breaks supplied by \code{ggplot2} as its only argument. The | ||
#'function was modeled after the syntax and approach of the labeling functions | ||
#'in the \code{scales::label_*} family. | ||
#' | ||
#'@importFrom stringr str_length | ||
#'@importFrom lubridate year month day | ||
#'@importFrom stats na.omit | ||
#' | ||
#'@examples | ||
#' | ||
#'# basic functionality | ||
#'abbr_years()(c(2010:2020)) | ||
#'abbr_years(full_by_year = 2000)(c(1990:2010)) | ||
#' | ||
#' | ||
#' # Default implementation - this will abbreviate all labels except the first | ||
#' # for both continuous and date scales. | ||
#' | ||
#' df2 <- dplyr::mutate(transit_ridership, year2 = as.Date(lubridate::date_decimal(year))) | ||
#' df1 <- dplyr::filter(df2, year >= 2000) | ||
#' | ||
#' ggplot(df1, | ||
#' aes(x = year, y = ridership, color = system)) + | ||
#' geom_line() + | ||
#' scale_x_continuous(labels = abbr_years()) | ||
#' | ||
#' ggplot(df1, | ||
#' aes(x = year2, y = ridership, color = system)) + | ||
#' geom_line() + | ||
#' scale_x_date(labels = abbr_years(dateaxis = TRUE)) | ||
#' | ||
#' # If customizations are desired, users can use \code{full_by_pos} and/or | ||
#' # \code{full_by_year} to maintain the full version of the specified labels. | ||
#' | ||
#' ggplot(df2, | ||
#' aes(x = year2, y = ridership, color = system)) + | ||
#' geom_line() + | ||
#' scale_x_date(labels = abbr_years(full_by_year = c(2000), dateaxis = TRUE)) | ||
#' | ||
#' # You can also remove the default maintenance of the first label and only | ||
#' # specify specific years. | ||
#' ggplot(df2, | ||
#' aes(x = year, y = ridership, color = system)) + | ||
#' geom_line() + | ||
#' scale_x_continuous(labels = abbr_years(full_by_pos = NULL, | ||
#' full_by_year = c(1990,2020))) | ||
#' | ||
#' | ||
#'@param full_by_pos Vector of integers, the position of breaks that should not | ||
#' be abbreviated. This defaults to \code{c(1)}, which retains the original | ||
#' first label and abbreviates subsequent ones. If all breaks should be | ||
#' abbreviated, this can be set to NULL. | ||
#'@param full_by_year Vector of integers, the value of breaks that should not be | ||
#' abbreviated. Defaults to NULL. | ||
#'@param dateaxis Bool. \code{FALSE}, the default, directs the function to treat | ||
#' the breaks as integers. If set to \code{TRUE} the function will instead | ||
#' treat the breaks as date objects. \code{TRUE} should be used when called | ||
#' within a \code{scale_*_date} ggplot element. | ||
#' | ||
#'@export | ||
abbr_years <- function(full_by_pos = c(1), | ||
full_by_year = NULL, | ||
dateaxis = FALSE) { | ||
|
||
fxn <- function(breaks) { | ||
|
||
# If a date axis, breaks are stored by ggplot as the number of days since | ||
# the origin date of January 1, 1970. These must be converted to integer | ||
# years, but this should error if all breaks don't fall on the same calendar | ||
# day of a distinct year. | ||
if (dateaxis) { | ||
dates <- as.Date(breaks, origin = "1970-01-01") | ||
|
||
if (length(unique(month(stats::na.omit(dates)))) != 1 | | ||
length(unique(day(stats::na.omit(dates)))) != 1) { | ||
message(paste( | ||
paste("Currently, breaks are:", paste(dates[!is.na(dates)], collapse = ", ")), | ||
"This function only works if all breaks are on identical calendar days.", | ||
sep = "\n") | ||
) | ||
stop("Breaks cannot be abbreviated.", call. = FALSE) | ||
} | ||
|
||
breaks <- lubridate::year(dates) | ||
} | ||
|
||
# Stop if the breaks are not in a four-digit format. | ||
if (!all(stringr::str_length(breaks) == 4, na.rm = TRUE)) { | ||
message(paste( | ||
paste("Currently, breaks are:", paste(breaks[!is.na(breaks)], collapse = ", ")), | ||
"Remove any breaks that contain decimals. Consider `breaks = scales::pretty_breaks()`", | ||
"If the axis is in date format, use `abbr_years(dateaxis = TRUE)`.", | ||
sep = "\n") | ||
) | ||
stop("Breaks cannot be abbreviated.", call. = FALSE) | ||
} | ||
|
||
# Abbreviate all values | ||
abbr <- paste0("'",substr(breaks,3,4)) | ||
|
||
# If there is a leading NA, increment up positions accordingly | ||
leading_na <- which.min(is.na(breaks)) - 1 | ||
if(!is.null(full_by_pos)) { | ||
full_by_pos <- full_by_pos + leading_na | ||
} | ||
|
||
# Convert specified years into positions | ||
if(!is.null(full_by_year)) { | ||
full_by_pos <- sort(unique(c(full_by_pos,match(full_by_year,breaks)))) | ||
} | ||
|
||
# Add back full years for specified positions | ||
abbr[full_by_pos] <- breaks[full_by_pos] | ||
|
||
return(abbr) | ||
} | ||
|
||
return(fxn) | ||
} |
Oops, something went wrong.