forked from tidyverse/ggplot2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom_segment.Rd
109 lines (88 loc) · 4.01 KB
/
geom_segment.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
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/geom-curve.r, R/geom-segment.r
\name{geom_curve}
\alias{geom_curve}
\alias{geom_segment}
\title{Line segments and curves.}
\usage{
geom_curve(mapping = NULL, data = NULL, stat = "identity",
position = "identity", curvature = 0.5, angle = 90, ncp = 5,
arrow = NULL, lineend = "butt", na.rm = FALSE, inherit.aes = TRUE,
...)
geom_segment(mapping = NULL, data = NULL, stat = "identity",
position = "identity", arrow = NULL, lineend = "butt", na.rm = FALSE,
show.legend = NA, inherit.aes = TRUE, ...)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
default), is combined with the default mapping at the top level of the
plot. You only need to supply \code{mapping} if there isn't a mapping
defined for the plot.}
\item{data}{A data frame. If specified, overrides the default data frame
defined at the top level of the plot.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
\item{curvature}{A numeric value giving the amount of curvature.
Negative values produce left-hand curves, positive values
produce right-hand curves, and zero produces a straight line.}
\item{angle}{A numeric value between 0 and 180,
giving an amount to skew the control
points of the curve. Values less than 90 skew the curve towards
the start point and values greater than 90 skew the curve
towards the end point.}
\item{ncp}{The number of control points used to draw the curve.
More control points creates a smoother curve.}
\item{arrow}{specification for arrow heads, as created by arrow()}
\item{lineend}{Line end style (round, butt, square)}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
\item{...}{Arguments to be passed to \code{curveGrob}.}
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.}
}
\description{
\code{geom_segment} draws a straight line between points (x1, y1) and
(x2, y2). \code{geom_curve} draws a curved line.
}
\section{Aesthetics}{
\Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "segment")}
}
\examples{
b <- ggplot(mtcars, aes(wt, mpg)) +
geom_point()
df <- data.frame(x1 = 2.62, x2 = 3.57, y1 = 21.0, y2 = 15.0)
b +
geom_curve(aes(x = x1, y = y1, xend = x2, yend = y2, colour = "curve"), data = df) +
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2, colour = "segment"), data = df)
b + geom_curve(aes(x = x1, y = y1, xend = x2, yend = y2), data = df, curvature = -0.2)
b + geom_curve(aes(x = x1, y = y1, xend = x2, yend = y2), data = df, curvature = 1)
b + geom_curve(
aes(x = x1, y = y1, xend = x2, yend = y2),
data = df,
arrow = arrow(length = unit(0.03, "npc"))
)
ggplot(seals, aes(long, lat)) +
geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat),
arrow = arrow(length = unit(0.1,"cm"))) +
borders("state")
# You can also use geom_segment to recreate plot(type = "h") :
counts <- as.data.frame(table(x = rpois(100,5)))
counts$x <- as.numeric(as.character(counts$x))
with(counts, plot(x, Freq, type = "h", lwd = 10))
ggplot(counts, aes(x, Freq)) +
geom_segment(aes(xend = x, yend = 0), size = 10, lineend = "butt")
}
\seealso{
\code{\link{geom_path}} and \code{\link{geom_line}} for multi-
segment lines and paths.
\code{\link{geom_spoke}} for a segment parameterised by a location
(x, y), and an angle and radius.
}