geom_segmentgeom_segment(mapping=NULL, data=NULL, stat="identity", position="identity", ...)
Single line segments
This page describes geom_segment, see layer and qplot for how to create a complete plot from individual components.
What do you think of the documentation? Please let me know by filling out this short online survey.
The following aesthetics can be used with geom_segment. Aesthetics are mapped to variables in the data with the aes function: geom_segment(aes(x = var)). Note that you do not need quotes around the variable name.
Scales control how the variable is mapped to the aesthetic and are listed after each aesthetic.
| Aesthetic | Default | Related scales |
|---|---|---|
| x | required | continuous, date, datetime, discrete |
| y | required | continuous, date, datetime, discrete |
| xend | required | |
| yend | required | |
| colour | black | brewer, gradient, gradient2, gradientn, grey, hue, identity, manual |
| size | 0.5 | identity, manual, size |
| linetype | 1 | identity, linetype, manual |
| alpha | 1 |
Layers are divided into groups by the group aesthetic. By default this is set to the interaction of all categorical variables present in the plot.
Parameters control the appearance of the geom. In addition to the parameters listed below (if any), any aesthetic can be used as a parameter, in which case it will override any aesthetic mapping.
arrow: specification for arrow heads, as created by arrow()This function returns a layer object.
> require("maps") > > xlim <- range(seals$long) > ylim <- range(seals$lat) > usamap <- data.frame(map("world", xlim = xlim, ylim = ylim, plot = + FALSE)[c("x","y")]) > usamap <- rbind(usamap, NA, data.frame(map('state', xlim = xlim, ylim + = ylim, plot = FALSE)[c("x","y")])) > names(usamap) <- c("long", "lat") > > p <- ggplot(seals, aes(x = long, y = lat)) > (p <- p + geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat), + arrow=arrow(length=unit(0.1,"cm"))))> p + geom_path(data = usamap) + scale_x_continuous(limits=xlim)
> > # 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)) > > qplot(x, Freq, data = counts, geom="segment", + yend = 0, xend = x, size = I(10))
>
What do you think of the documentation? Please let me know by filling out this short online survey.