-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathcoord_polar.Rd
153 lines (132 loc) · 5.39 KB
/
coord_polar.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coord-polar.R, R/coord-radial.R
\name{coord_polar}
\alias{coord_polar}
\alias{coord_radial}
\title{Polar coordinates}
\usage{
coord_polar(theta = "x", start = 0, direction = 1, clip = "on")
coord_radial(
theta = "x",
start = 0,
end = NULL,
thetalim = NULL,
rlim = NULL,
expand = TRUE,
direction = deprecated(),
clip = "off",
r.axis.inside = NULL,
rotate.angle = FALSE,
inner.radius = 0,
reverse = "none",
r_axis_inside = deprecated(),
rotate_angle = deprecated()
)
}
\arguments{
\item{theta}{variable to map angle to (\code{x} or \code{y})}
\item{start}{Offset of starting point from 12 o'clock in radians. Offset
is applied clockwise or anticlockwise depending on value of \code{direction}.}
\item{direction}{1, clockwise; -1, anticlockwise}
\item{clip}{Should drawing be clipped to the extent of the plot panel? A
setting of \code{"on"} (the default) means yes, and a setting of \code{"off"}
means no. For details, please see \code{\link[=coord_cartesian]{coord_cartesian()}}.}
\item{end}{Position from 12 o'clock in radians where plot ends, to allow
for partial polar coordinates. The default, \code{NULL}, is set to
\code{start + 2 * pi}.}
\item{thetalim, rlim}{Limits for the theta and r axes.}
\item{expand}{If \code{TRUE}, the default, adds a small expansion factor to
the limits to prevent overlap between data and axes. If \code{FALSE}, limits
are taken directly from the scale.}
\item{r.axis.inside}{One of the following:
\itemize{
\item \code{NULL} (default) places the axis next to the panel if \code{start} and
\code{end} arguments form a full circle and inside the panel otherwise.
\item \code{TRUE} to place the radius axis inside the panel.
\item \code{FALSE} to place the radius axis next to the panel.
\item A numeric value, setting a theta axis value at which
the axis should be placed inside the panel. Can be given as a length 2
vector to control primary and secondary axis placement separately.
}}
\item{rotate.angle}{If \code{TRUE}, transforms the \code{angle} aesthetic in data
in accordance with the computed \code{theta} position. If \code{FALSE} (default),
no such transformation is performed. Can be useful to rotate text geoms in
alignment with the coordinates.}
\item{inner.radius}{A \code{numeric} between 0 and 1 setting the size of a
inner radius hole.}
\item{reverse}{A string giving which directions to reverse. \code{"none"}
(default) keep directions as is. \code{"theta"} reverses the angle and \code{"r"}
reverses the radius. \code{"thetar"} reverses both the angle and the radius.}
\item{r_axis_inside, rotate_angle}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}}
}
\description{
The polar coordinate system is most commonly used for pie charts, which
are a stacked bar chart in polar coordinates. \code{coord_radial()} has extended
options.
}
\note{
In \code{coord_radial()}, position guides can be defined by using
\code{guides(r = ..., theta = ..., r.sec = ..., theta.sec = ...)}. Note that
these guides require \code{r} and \code{theta} as available aesthetics. The classic
\code{\link[=guide_axis]{guide_axis()}} can be used for the \code{r} positions and \code{\link[=guide_axis_theta]{guide_axis_theta()}} can
be used for the \code{theta} positions. Using the \code{theta.sec} position is only
sensible when \code{inner.radius > 0}.
}
\examples{
# NOTE: Use these plots with caution - polar coordinates has
# major perceptual problems. The main point of these examples is
# to demonstrate how these common plots can be described in the
# grammar. Use with EXTREME caution.
# A pie chart = stacked bar chart + polar coordinates
pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) +
geom_bar(width = 1)
pie + coord_polar(theta = "y")
\donttest{
# A coxcomb plot = bar chart + polar coordinates
cxc <- ggplot(mtcars, aes(x = factor(cyl))) +
geom_bar(width = 1, colour = "black")
cxc + coord_polar()
# A new type of plot?
cxc + coord_polar(theta = "y")
# The bullseye chart
pie + coord_polar()
# Hadley's favourite pie chart
df <- data.frame(
variable = c("does not resemble", "resembles"),
value = c(20, 80)
)
ggplot(df, aes(x = "", y = value, fill = variable)) +
geom_col(width = 1) +
scale_fill_manual(values = c("red", "yellow")) +
coord_polar("y", start = pi / 3) +
labs(title = "Pac man")
# Windrose + doughnut plot
if (require("ggplot2movies")) {
movies$rrating <- cut_interval(movies$rating, length = 1)
movies$budgetq <- cut_number(movies$budget, 4)
doh <- ggplot(movies, aes(x = rrating, fill = budgetq))
# Wind rose
doh + geom_bar(width = 1) + coord_polar()
# Race track plot
doh + geom_bar(width = 0.9, position = "fill") + coord_polar(theta = "y")
}
}
# A partial polar plot
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
coord_radial(start = -0.4 * pi, end = 0.4 * pi, inner.radius = 0.3)
# Similar with coord_cartesian(), you can set limtis, but note the `clip`
# area is not the same with the circle track area.
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
coord_radial(
start = -0.4 * pi,
end = 0.4 * pi, inner.radius = 0.3,
thetalim = c(200, 300),
rlim = c(15, 30),
clip = "on"
)
}
\seealso{
The \href{https://ggplot2-book.org/coord#polar-coordinates-with-coord_polar}{polar coordinates section} of the online ggplot2 book.
}