Skip to content

Commit

Permalink
scale_size_area: default to area proportional to data value
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Sep 19, 2012
1 parent 53912e7 commit 72d15fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Imports:
grid, grid,
gtable (>= 0.1.1), gtable (>= 0.1.1),
reshape2, reshape2,
scales (>= 0.2.2), scales (>= 0.2.2.99.1),
proto, proto,
MASS MASS
Suggests: Suggests:
Expand Down
9 changes: 9 additions & 0 deletions R/scale-area.r
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,18 @@
#' Scale area instead of radius (for size). #' Scale area instead of radius (for size).
#' #'
#' \code{\link{scale_area}} is deprecated and will be removed in a future
#' version of ggplot2. Use \code{\link{scale_size_area}} instead. Note that the
#' default behavir of \code{\link{scale_size_area}} is slightly different: by
#' default, it makes the area proportional to the numeric value.
#'
#' @param ... Other arguments passed on to \code{\link{continuous_scale}} #' @param ... Other arguments passed on to \code{\link{continuous_scale}}
#' to control name, limits, breaks, labels and so forth. #' to control name, limits, breaks, labels and so forth.
#' @param range Range of output sizes. Should be greater than 0. #' @param range Range of output sizes. Should be greater than 0.
#' @export #' @export
scale_area <- function(..., range = c(1, 6)) { scale_area <- function(..., range = c(1, 6)) {
message("scale_area is deprecated and will be removed in a future version of ggplot2.\n",
" Use scale_size_area instead. Note that the behavior of scale_size_area is\n",
" slightly different: by default it makes the area proportional to the\n",
" numeric value.")
continuous_scale("size", "area", area_pal(range), ...) continuous_scale("size", "area", area_pal(range), ...)
} }
20 changes: 20 additions & 0 deletions R/scale-size.r
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,3 +44,23 @@ scale_size_discrete <- function(..., range = c(1, 6)) {
discrete_scale("size", "size_d", discrete_scale("size", "size_d",
function(n) seq(range[1], range[2], length = n), ...) function(n) seq(range[1], range[2], length = n), ...)
} }

#' Scale area instead of radius, for size.
#'
#' When \code{scale_size_area} is used, the default behavior is to scale the
#' area of points to be proportional to the value.
#'
#' Note that this controls the size scale, so it will also control
#' the thickness of lines. Line thickness will be proportional to the square
#' root of the value, which is probably undesirable in most cases.
#'
#' @param ... Other arguments passed on to \code{\link{continuous_scale}}
#' to control name, limits, breaks, labels and so forth.
#' @param range Range of output sizes. Should be greater than 0.
#' @param max_size Size of largest points.
#' @export
scale_size_area <- function(..., max_size = 6) {
continuous_scale("size", "area",
pal = abs_area(max_size),
rescaler = rescale_max, ...)
}

0 comments on commit 72d15fc

Please sign in to comment.