Skip to content

Commit b661848

Browse files
committed
move and merge docs to coord_radial()
1 parent 09b9020 commit b661848

File tree

3 files changed

+64
-68
lines changed

3 files changed

+64
-68
lines changed

R/coord-polar.R

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,5 @@
1-
#' Polar coordinates
2-
#'
3-
#' The polar coordinate system is most commonly used for pie charts, which
4-
#' are a stacked bar chart in polar coordinates. `coord_radial()` has extended
5-
#' options.
6-
#'
7-
#' @param theta variable to map angle to (`x` or `y`)
8-
#' @param start Offset of starting point from 12 o'clock in radians. Offset
9-
#' is applied clockwise or anticlockwise depending on value of `direction`.
10-
#' @param direction 1, clockwise; -1, anticlockwise
11-
#' @param clip Should drawing be clipped to the extent of the plot panel? A
12-
#' setting of `"on"` (the default) means yes, and a setting of `"off"`
13-
#' means no. For details, please see [`coord_cartesian()`].
1+
#' @rdname coord_radial
142
#' @export
15-
#' @seealso
16-
#' The `r link_book("polar coordinates section", "coord#polar-coordinates-with-coord_polar")`
17-
#' @examples
18-
#' # NOTE: Use these plots with caution - polar coordinates has
19-
#' # major perceptual problems. The main point of these examples is
20-
#' # to demonstrate how these common plots can be described in the
21-
#' # grammar. Use with EXTREME caution.
22-
#'
23-
#' # A pie chart = stacked bar chart + polar coordinates
24-
#' pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) +
25-
#' geom_bar(width = 1)
26-
#' pie + coord_radial(theta = "y", expand = FALSE)
27-
#'
28-
#' \donttest{
29-
#'
30-
#' # A coxcomb plot = bar chart + polar coordinates
31-
#' cxc <- ggplot(mtcars, aes(x = factor(cyl))) +
32-
#' geom_bar(width = 1, colour = "black")
33-
#' cxc + coord_radial(expand = FALSE)
34-
#' # A new type of plot?
35-
#' cxc + coord_radial(theta = "y", expand = FALSE)
36-
#'
37-
#' # The bullseye chart
38-
#' pie + coord_radial(expand = FALSE)
39-
#'
40-
#' # Hadley's favourite pie chart
41-
#' df <- data.frame(
42-
#' variable = c("does not resemble", "resembles"),
43-
#' value = c(20, 80)
44-
#' )
45-
#' ggplot(df, aes(x = "", y = value, fill = variable)) +
46-
#' geom_col(width = 1) +
47-
#' scale_fill_manual(values = c("red", "yellow")) +
48-
#' coord_radial("y", start = pi / 3, expand = FALSE) +
49-
#' labs(title = "Pac man")
50-
#'
51-
#' # Windrose + doughnut plot
52-
#' if (require("ggplot2movies")) {
53-
#' movies$rrating <- cut_interval(movies$rating, length = 1)
54-
#' movies$budgetq <- cut_number(movies$budget, 4)
55-
#'
56-
#' doh <- ggplot(movies, aes(x = rrating, fill = budgetq))
57-
#'
58-
#' # Wind rose
59-
#' doh + geom_bar(width = 1) + coord_radial(expand = FALSE)
60-
#' # Race track plot
61-
#' doh + geom_bar(width = 0.9, position = "fill") +
62-
#' coord_radial(theta = "y", expand = FALSE)
63-
#' }
64-
#' }
653
coord_polar <- function(theta = "x", start = 0, direction = 1, clip = "on") {
664
theta <- arg_match0(theta, c("x", "y"))
675
r <- if (theta == "x") "y" else "x"

R/coord-radial.R

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
2-
#' @rdname coord_polar
1+
#' Polar coordinates
2+
#'
3+
#' The polar coordinate system is most commonly used for pie charts, which
4+
#' are a stacked bar chart in polar coordinates. `coord_radial()` has extended
5+
#' options.
36
#'
7+
#' @param theta variable to map angle to (`x` or `y`)
8+
#' @param start Offset of starting point from 12 o'clock in radians. Offset
9+
#' is applied clockwise or anticlockwise depending on value of `direction`.
10+
#' @param direction 1, clockwise; -1, anticlockwise
11+
#' @param clip Should drawing be clipped to the extent of the plot panel? A
12+
#' setting of `"on"` (the default) means yes, and a setting of `"off"`
13+
#' means no. For details, please see [`coord_cartesian()`].
414
#' @param end Position from 12 o'clock in radians where plot ends, to allow
515
#' for partial polar coordinates. The default, `NULL`, is set to
616
#' `start + 2 * pi`.
@@ -26,7 +36,7 @@
2636
#' (default) keep directions as is. `"theta"` reverses the angle and `"r"`
2737
#' reverses the radius. `"thetar"` reverses both the angle and the radius.
2838
#' @param r_axis_inside,rotate_angle `r lifecycle::badge("deprecated")`
29-
#'
39+
#' @export
3040
#' @note
3141
#' In `coord_radial()`, position guides can be defined by using
3242
#' `guides(r = ..., theta = ..., r.sec = ..., theta.sec = ...)`. Note that
@@ -35,8 +45,56 @@
3545
#' be used for the `theta` positions. Using the `theta.sec` position is only
3646
#' sensible when `inner.radius > 0`.
3747
#'
38-
#' @export
48+
#' @seealso
49+
#' The `r link_book("polar coordinates section", "coord#polar-coordinates-with-coord_polar")`
3950
#' @examples
51+
#' # NOTE: Use these plots with caution - polar coordinates has
52+
#' # major perceptual problems. The main point of these examples is
53+
#' # to demonstrate how these common plots can be described in the
54+
#' # grammar. Use with EXTREME caution.
55+
#'
56+
#' # A pie chart = stacked bar chart + polar coordinates
57+
#' pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) +
58+
#' geom_bar(width = 1)
59+
#' pie + coord_radial(theta = "y", expand = FALSE)
60+
#'
61+
#' \donttest{
62+
#'
63+
#' # A coxcomb plot = bar chart + polar coordinates
64+
#' cxc <- ggplot(mtcars, aes(x = factor(cyl))) +
65+
#' geom_bar(width = 1, colour = "black")
66+
#' cxc + coord_radial(expand = FALSE)
67+
#' # A new type of plot?
68+
#' cxc + coord_radial(theta = "y", expand = FALSE)
69+
#'
70+
#' # The bullseye chart
71+
#' pie + coord_radial(expand = FALSE)
72+
#'
73+
#' # Hadley's favourite pie chart
74+
#' df <- data.frame(
75+
#' variable = c("does not resemble", "resembles"),
76+
#' value = c(20, 80)
77+
#' )
78+
#' ggplot(df, aes(x = "", y = value, fill = variable)) +
79+
#' geom_col(width = 1) +
80+
#' scale_fill_manual(values = c("red", "yellow")) +
81+
#' coord_radial("y", start = pi / 3, expand = FALSE) +
82+
#' labs(title = "Pac man")
83+
#'
84+
#' # Windrose + doughnut plot
85+
#' if (require("ggplot2movies")) {
86+
#' movies$rrating <- cut_interval(movies$rating, length = 1)
87+
#' movies$budgetq <- cut_number(movies$budget, 4)
88+
#'
89+
#' doh <- ggplot(movies, aes(x = rrating, fill = budgetq))
90+
#'
91+
#' # Wind rose
92+
#' doh + geom_bar(width = 1) + coord_radial(expand = FALSE)
93+
#' # Race track plot
94+
#' doh + geom_bar(width = 0.9, position = "fill") +
95+
#' coord_radial(theta = "y", expand = FALSE)
96+
#' }
97+
#' }
4098
#' # A partial polar plot
4199
#' ggplot(mtcars, aes(disp, mpg)) +
42100
#' geom_point() +
@@ -475,7 +533,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
475533
}
476534
)
477535

478-
view_scales_polar <- function(scale, theta = "x", coord_limits = NULL,
536+
view_scales_polar <- function(scale, theta = "x", coord_limits = NULL,
479537
expand = TRUE) {
480538

481539
aesthetic <- scale$aesthetics[1]
File renamed without changes.

0 commit comments

Comments
 (0)