Skip to content

Commit

Permalink
wikis scale fns
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkenny committed Aug 15, 2023
1 parent 24bf8a5 commit 3d70b5d
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 1 deletion.
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export(scale_color_party_c)
export(scale_color_party_d)
export(scale_color_penn82)
export(scale_color_randmcnally)
export(scale_color_wiki_dem)
export(scale_color_wiki_dem_pres)
export(scale_color_wiki_rep)
export(scale_color_wiki_rep_pres)
export(scale_colour_coast)
export(scale_colour_dra)
export(scale_colour_larch)
Expand All @@ -46,6 +50,10 @@ export(scale_fill_party_c)
export(scale_fill_party_d)
export(scale_fill_penn82)
export(scale_fill_randmcnally)
export(scale_fill_wiki_dem)
export(scale_fill_wiki_dem_pres)
export(scale_fill_wiki_rep)
export(scale_fill_wiki_rep_pres)
export(stat_cities)
export(stat_district)
export(stat_district_coordinates)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ggredist 0.0.2

* Adds colors and scales to match Wikipedia's typical election mapping colors.

# ggredist 0.0.1

* Added a `NEWS.md` file to track changes to the package.
Expand Down
2 changes: 1 addition & 1 deletion R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ggredist = list(
wiki_dem = structure(c('#EBF2FF', '#DFEEFF', '#BDD3FF', '#A5B0FF', '#7996E2',
'#6674DE', '#584CDE', '#3933E5', '#0D0596'),
class = c("palette", 'character')),
wiki_dem = structure(c('#FFF0F5', '#FFE0EA', '#FFC8CD', '#FFB2B2', '#E27F7F',
wiki_rep = structure(c('#FFF0F5', '#FFE0EA', '#FFC8CD', '#FFB2B2', '#E27F7F',
'#D75D5D', '#D72F30', '#C21B18', '#A80000'),
class = c("palette", 'character')),
wiki_proposal = structure(c('#2B2457', '#28497C', '#47729E', '#7D9CBB', '#B6C8D9',
Expand Down
134 changes: 134 additions & 0 deletions R/wiki.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#' Wikipedia Election Map scales for `ggplot2`
#'
#' @rdname scale_wiki
#'
#' @param ... additional arguments to `ggplot::scale_*` functions
#'
#' @return ggplot scale function
#'
#' @examples
#' scale_fill_wiki_rep()
#' scale_fill_wiki_rep()
#' scale_fill_wiki_dem()
#' scale_fill_wiki_dem()
#' scale_fill_wiki_rep_pres()
#' scale_fill_wiki_rep_pres()
#' scale_fill_wiki_dem_pres()
#' scale_fill_wiki_dem_pres()
#' @concept colors
#' @export
scale_fill_wiki_rep <- function(...) {
ggplot2::binned_scale('fill', 'wiki_rep',
palette = function(x) ggredist$wiki_rep,
breaks = seq(0, 1, by = 0.1),
limits = c(.1, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}

#' @rdname scale_wiki
#'
#' @concept colors
#' @export
scale_color_wiki_rep <- function(...) {
ggplot2::binned_scale('color', 'wiki_rep',
palette = function(x) ggredist$wiki_rep,
breaks = seq(0, 1, by = 0.1),
limits = c(.1, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}

#' @rdname scale_wiki
#'
#' @concept colors
#' @export
scale_fill_wiki_dem <- function(...) {
ggplot2::binned_scale('fill', 'wiki_dem',
palette = function(x) ggredist$wiki_dem,
breaks = seq(0, 1, by = 0.1),
limits = c(.1, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}

#' @rdname scale_wiki
#'
#' @concept colors
#' @export
scale_color_wiki_dem <- function(...) {
ggplot2::binned_scale('color', 'wiki_dem',
palette = function(x) ggredist$wiki_dem,
breaks = seq(0, 1, by = 0.1),
limits = c(.1, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}

#' @rdname scale_wiki
#'
#' @concept colors
#' @export
scale_fill_wiki_rep_pres <- function(...) {
ggplot2::binned_scale('fill', 'wiki_rep_pres',
palette = function(x) ggredist$wiki_rep_pres,
breaks = c(0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1),
limits = c(.2, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}

#' @rdname scale_wiki
#'
#' @concept colors
#' @export
scale_color_wiki_rep_pres <- function(...) {
ggplot2::binned_scale('color', 'wiki_rep_pres',
palette = function(x) ggredist$wiki_rep_pres,
breaks = c(0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1),
limits = c(.2, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}

#' @rdname scale_wiki
#'
#' @concept colors
#' @export
scale_fill_wiki_dem_pres <- function(...) {
ggplot2::binned_scale('fill', 'wiki_dem_pres',
palette = function(x) ggredist$wiki_dem_pres,
breaks = c(0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1),
limits = c(.2, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}

#' @rdname scale_wiki
#'
#' @concept colors
#' @export
scale_color_wiki_dem_pres <- function(...) {
ggplot2::binned_scale('color', 'wiki_dem_pres',
palette = function(x) ggredist$wiki_dem_pres,
breaks = c(0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1),
limits = c(.2, .9),
oob = scales::squish,
guide = 'colourbar',
...
)
}
49 changes: 49 additions & 0 deletions man/scale_wiki.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d70b5d

Please sign in to comment.