|
4 | 4 | #' @param end Position from 12 o'clock in radians where plot ends, to allow
|
5 | 5 | #' for partial polar coordinates. The default, `NULL`, is set to
|
6 | 6 | #' `start + 2 * pi`.
|
| 7 | +#' @inheritParams coord_cartesian |
7 | 8 | #' @param expand If `TRUE`, the default, adds a small expansion factor to
|
8 | 9 | #' the limits to prevent overlap between data and axes. If `FALSE`, limits
|
9 | 10 | #' are taken directly from the scale.
|
|
40 | 41 | #' ggplot(mtcars, aes(disp, mpg)) +
|
41 | 42 | #' geom_point() +
|
42 | 43 | #' coord_radial(start = -0.4 * pi, end = 0.4 * pi, inner.radius = 0.3)
|
| 44 | +#' |
| 45 | +#' # Similar with coord_cartesian(), you can set limtis, but note the `clip` |
| 46 | +#' # area is not the same with the circle track area. |
| 47 | +#' ggplot(mtcars, aes(disp, mpg)) + |
| 48 | +#' geom_point() + |
| 49 | +#' coord_radial( |
| 50 | +#' start = -0.4 * pi, |
| 51 | +#' end = 0.4 * pi, inner.radius = 0.3, |
| 52 | +#' xlim = c(200, 300), |
| 53 | +#' ylim = c(15, 30), |
| 54 | +#' clip = "on" |
| 55 | +#' ) |
43 | 56 | coord_radial <- function(theta = "x",
|
44 | 57 | start = 0, end = NULL,
|
45 |
| - expand = TRUE, |
| 58 | + xlim = NULL, ylim = NULL, expand = TRUE, |
46 | 59 | direction = deprecated(),
|
47 | 60 | clip = "off",
|
48 | 61 | r.axis.inside = NULL,
|
@@ -96,6 +109,7 @@ coord_radial <- function(theta = "x",
|
96 | 109 | inner.radius <- switch(reverse, thetar = , r = rev, identity)(inner.radius)
|
97 | 110 |
|
98 | 111 | ggproto(NULL, CoordRadial,
|
| 112 | + limits = list(x = xlim, y = ylim), |
99 | 113 | theta = theta,
|
100 | 114 | r = r,
|
101 | 115 | arc = arc,
|
@@ -149,8 +163,12 @@ CoordRadial <- ggproto("CoordRadial", Coord,
|
149 | 163 | setup_panel_params = function(self, scale_x, scale_y, params = list()) {
|
150 | 164 |
|
151 | 165 | params <- c(
|
152 |
| - view_scales_polar(scale_x, self$theta, expand = params$expand[c(4, 2)]), |
153 |
| - view_scales_polar(scale_y, self$theta, expand = params$expand[c(3, 1)]), |
| 166 | + view_scales_polar(scale_x, self$theta, self$limits$x, |
| 167 | + expand = params$expand[c(4, 2)] |
| 168 | + ), |
| 169 | + view_scales_polar(scale_y, self$theta, self$limits$y, |
| 170 | + expand = params$expand[c(3, 1)] |
| 171 | + ), |
154 | 172 | list(bbox = polar_bbox(self$arc, inner_radius = self$inner_radius),
|
155 | 173 | arc = self$arc, inner_radius = self$inner_radius)
|
156 | 174 | )
|
@@ -454,15 +472,19 @@ CoordRadial <- ggproto("CoordRadial", Coord,
|
454 | 472 | }
|
455 | 473 | )
|
456 | 474 |
|
457 |
| -view_scales_polar <- function(scale, theta = "x", expand = TRUE) { |
| 475 | +view_scales_polar <- function(scale, theta = "x", coord_limits = NULL, |
| 476 | + expand = TRUE) { |
458 | 477 |
|
459 | 478 | aesthetic <- scale$aesthetics[1]
|
460 | 479 | is_theta <- theta == aesthetic
|
461 | 480 | name <- if (is_theta) "theta" else "r"
|
462 | 481 |
|
463 | 482 | expansion <- default_expansion(scale, expand = expand)
|
464 | 483 | limits <- scale$get_limits()
|
465 |
| - continuous_range <- expand_limits_scale(scale, expansion, limits) |
| 484 | + continuous_range <- expand_limits_scale( |
| 485 | + scale, expansion, limits, |
| 486 | + coord_limits |
| 487 | + ) |
466 | 488 |
|
467 | 489 | primary <- view_scale_primary(scale, limits, continuous_range)
|
468 | 490 | view_scales <- list(
|
|
0 commit comments