File: coord_polar.rd

package info (click to toggle)
r-cran-ggplot2 0.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,084 kB
  • sloc: makefile: 3
file content (71 lines) | stat: -rw-r--r-- 2,429 bytes parent folder | download
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
\name{coord_polar}
\alias{coord_polar}
\alias{CoordPolar}
\title{coord\_polar}
\description{Polar coordinates}
\details{
The polar coordinate system is most commonly used for pie charts, which are a stacked bar chart in polar coordinates.


This coordinate system has one argument, \code{theta}, which determines which variable is mapped to angle and which to radius.  Valid values are "x" and "y".

This page describes coord\_polar, see \code{\link{layer}} and \code{\link{qplot}} for how to create a complete plot from individual components.
}
\usage{coord_polar(theta = "x", start = 0, direction = 1, expand = FALSE, 
    ...)}
\arguments{
 \item{theta}{variable to map angle to ('x' or 'y')}
 \item{start}{offset from 12 o'clock in radians}
 \item{direction}{1, clockwise; -1, anticlockwise}
 \item{expand}{should axes be expanded to slightly outside the range of the data? (default: FALSE)}
 \item{...}{other arguments}
}
\seealso{\itemize{
  \item \url{http://had.co.nz/ggplot2/coord_polar.html}
}}
\value{A \code{\link{layer}}}
\examples{\dontrun{
# 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 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")

# 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")

# The bullseye chart
pie + coord_polar()

# Hadley's favourite pie chart
df <- data.frame(
  variable = c("resembles", "does not resemble"),
  value = c(80, 20)
)
ggplot(df, aes(x = "", y = value, fill = variable)) + 
  geom_bar(width = 1) + 
  scale_fill_manual(values = c("red", "yellow")) + 
  coord_polar("y", start=pi / 3) + 
  opts(title = "Pac man")

# Windrose + doughnut plot
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")
}}
\author{Hadley Wickham, \url{http://had.co.nz/}}
\keyword{hplot}