| geom_line {ggplot2} | R Documentation |
Connect observations, in ordered by x value
geom_line(mapping=NULL, data=NULL, stat="identity", position="identity", ...)
mapping |
mapping between variables and aesthetics generated by aes |
data |
dataset used in this layer, if not specified uses plot dataset |
stat |
statistic used by this layer |
position |
position adjustment used by this layer |
... |
ignored |
This page describes geom_line, see layer and qplot for how to create a complete plot from individual components.
A layer
The following aesthetics can be used with geom_line. Aesthetics are mapped to variables in the data with the aes function: geom\_line(\code{aes}(x = var))
x: x position (required)
y: y position (required)
colour: border colour
size: size
linetype: line type
Hadley Wickham, http://had.co.nz/
geom_path: Connect observations, in original order
geom_segment: Line segments
geom_ribbon: Fill between line and x-axis
## Not run:
# Summarise number of movie ratings by year of movie
mry <- do.call(rbind, by(movies, round(movies$rating), function(df) {
nums <- tapply(df$length, df$year, length)
data.frame(rating=round(df$rating[1]), year = as.numeric(names(nums)), number=as.vector(nums))
}))
p <- ggplot(mry, aes(x=year, y=number, group=rating))
p + geom_line()
# Add aesthetic mappings
p + geom_line(aes(size = rating))
p + geom_line(aes(colour = rating))
# Change scale
p + geom_line(aes(colour = rating)) + scale_colour_gradient(low="red")
# Set aesthetics to fixed value
p + geom_line(colour = "red", size = 1)
# Use qplot instead
qplot(year, number, data=mry, group=rating, geom="line")
# Using a time series
qplot(date, pop, data=economics, geom="line")
qplot(date, pop, data=economics, geom="line", log="y")
qplot(date, pop, data=subset(economics, date > as.Date("2006-1-1")), geom="line")
qplot(date, pop, data=economics, size=unemploy/pop, geom="line")
## End(Not run)