|
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 |
14 | 2 | #' @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_polar(theta = "y") |
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_polar() |
34 | | -#' # A new type of plot? |
35 | | -#' cxc + coord_polar(theta = "y") |
36 | | -#' |
37 | | -#' # The bullseye chart |
38 | | -#' pie + coord_polar() |
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_polar("y", start = pi / 3) + |
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_polar() |
60 | | -#' # Race track plot |
61 | | -#' doh + geom_bar(width = 0.9, position = "fill") + coord_polar(theta = "y") |
62 | | -#' } |
63 | | -#' } |
64 | 3 | coord_polar <- function(theta = "x", start = 0, direction = 1, clip = "on") { |
65 | 4 | theta <- arg_match0(theta, c("x", "y")) |
66 | 5 | r <- if (theta == "x") "y" else "x" |
| 6 | + lifecycle::signal_stage("superseded", "coord_polar()", "coord_radial()") |
67 | 7 |
|
68 | 8 | ggproto(NULL, CoordPolar, |
69 | 9 | theta = theta, |
|
0 commit comments