Skip to content

Commit

Permalink
Add (default) scales for height and width aesthetics
Browse files Browse the repository at this point in the history
  • Loading branch information
willgearty committed Jul 30, 2024
1 parent 708b78e commit dba13db
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Imports:
methods,
lifecycle,
pbapply,
knitr
knitr,
scales
Suggests:
testthat (>= 3.0.0),
vdiffr (>= 1.0.0),
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ export(recolor_phylopic)
export(resolve_phylopic)
export(rotate_phylopic)
export(save_phylopic)
export(scale_height_continuous)
export(scale_width_continuous)
importFrom(curl,nslookup)
importFrom(ggplot2,Geom)
importFrom(ggplot2,aes)
importFrom(ggplot2,annotate)
importFrom(ggplot2,continuous_scale)
importFrom(ggplot2,coord_equal)
importFrom(ggplot2,element_text)
importFrom(ggplot2,expansion)
Expand All @@ -40,6 +43,7 @@ importFrom(ggplot2,layer)
importFrom(ggplot2,remove_missing)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_void)
importFrom(ggplot2,waiver)
importFrom(grDevices,bmp)
importFrom(grDevices,col2rgb)
importFrom(grDevices,dev.off)
Expand Down Expand Up @@ -81,6 +85,7 @@ importFrom(pbapply,pblapply)
importFrom(png,readPNG)
importFrom(rsvg,rsvg_png)
importFrom(rsvg,rsvg_svg)
importFrom(scales,pal_area)
importFrom(stats,setNames)
importFrom(utils,URLdecode)
importFrom(utils,URLencode)
Expand Down
34 changes: 34 additions & 0 deletions R/geom_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,40 @@ phylopicGrob <- function(img, x, y, height, width,
return(img_grob)
}

#' Scales for phylopic heighgt or width
#'
#' `scale_height_continuous()` scales the height of silhouettes whereas
#' `scale_width_continuous()` scales the height of silhouettes.
#' @inheritParams ggplot2::scale_size_continuous
#' @export
#' @importFrom ggplot2 continuous_scale waiver
#' @importFrom scales pal_area
#' @rdname scales
scale_height_continuous <- function(name = waiver(), breaks = waiver(), labels = waiver(),
limits = NULL, range = c(1, 6),
transform = "identity",
trans = lifecycle::deprecated(),
guide = "none") {
continuous_scale("height", palette = scales::pal_area(range), name = name,
breaks = breaks, labels = labels, limits = limits,
transform = transform, trans = trans, guide = guide)
}

#' @inheritParams ggplot2::scale_size_continuous
#' @export
#' @importFrom ggplot2 continuous_scale waiver
#' @importFrom scales pal_area
#' @rdname scales
scale_width_continuous <- function(name = waiver(), breaks = waiver(), labels = waiver(),
limits = NULL, range = c(1, 6),
transform = "identity",
trans = lifecycle::deprecated(),
guide = "none") {
continuous_scale("width", palette = scales::pal_area(range), name = name,
breaks = breaks, labels = labels, limits = limits,
transform = transform, trans = trans, guide = guide)
}

#' @importFrom grid grobName
ggname <- function(prefix, grob) {
# copied from ggplot2
Expand Down
98 changes: 98 additions & 0 deletions man/scales.Rd

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

0 comments on commit dba13db

Please sign in to comment.