Skip to content
This repository
Browse code

scale_size_area: default to area proportional to data value

  • Loading branch information...
commit 72d15fc057aec4050ac04e8991970168c84d5e9c 1 parent 53912e7
Winston Chang authored September 09, 2012
2  DESCRIPTION
@@ -23,7 +23,7 @@ Imports:
23 23
     grid,
24 24
     gtable (>= 0.1.1),
25 25
     reshape2,
26  
-    scales (>= 0.2.2),
  26
+    scales (>= 0.2.2.99.1),
27 27
     proto,
28 28
     MASS
29 29
 Suggests:
9  R/scale-area.r
... ...
@@ -1,9 +1,18 @@
1 1
 #' Scale area instead of radius (for size).
2 2
 #'
  3
+#' \code{\link{scale_area}} is deprecated and will be removed in a future
  4
+#' version of ggplot2. Use \code{\link{scale_size_area}} instead. Note that the
  5
+#' default behavir of \code{\link{scale_size_area}} is slightly different: by
  6
+#' default, it makes the area proportional to the numeric value.
  7
+#'
3 8
 #' @param ... Other arguments passed on to \code{\link{continuous_scale}} 
4 9
 #'   to control name, limits, breaks, labels and so forth.
5 10
 #' @param range Range of output sizes.  Should be greater than 0.
6 11
 #' @export
7 12
 scale_area <- function(..., range = c(1, 6)) {
  13
+  message("scale_area is deprecated and will be removed in a future version of ggplot2.\n",
  14
+    "  Use scale_size_area instead. Note that the behavior of scale_size_area is\n",
  15
+    "  slightly different: by default it makes the area proportional to the\n",
  16
+    "  numeric value.")
8 17
   continuous_scale("size", "area", area_pal(range), ...)
9 18
 }
20  R/scale-size.r
@@ -44,3 +44,23 @@ scale_size_discrete <- function(..., range = c(1, 6)) {
44 44
   discrete_scale("size", "size_d",
45 45
     function(n) seq(range[1], range[2], length = n), ...)
46 46
 }
  47
+
  48
+#' Scale area instead of radius, for size.
  49
+#'
  50
+#' When \code{scale_size_area} is used, the default behavior is to scale the
  51
+#' area of points to be proportional to the value.
  52
+#'
  53
+#' Note that this controls the size scale, so it will also control
  54
+#' the thickness of lines. Line thickness will be proportional to the square
  55
+#' root of the value, which is probably undesirable in most cases.
  56
+#'
  57
+#' @param ... Other arguments passed on to \code{\link{continuous_scale}}
  58
+#'   to control name, limits, breaks, labels and so forth.
  59
+#' @param range Range of output sizes.  Should be greater than 0.
  60
+#' @param max_size Size of largest points.
  61
+#' @export
  62
+scale_size_area <- function(..., max_size = 6) {
  63
+  continuous_scale("size", "area",
  64
+    pal = abs_area(max_size),
  65
+    rescaler = rescale_max, ...)
  66
+}

0 notes on commit 72d15fc

Please sign in to comment.
Something went wrong with that request. Please try again.