geom_linegeom_line(mapping=NULL, data=NULL, stat="identity", position="identity", ...)
Connect observations, in ordered by x value
This page describes geom_line, 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_line. Aesthetics are mapped to variables in the data with the aes function: geom_line(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 |
| 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: NULLThis function returns a layer object.
> # 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")
> p + geom_line(aes(size = rating)) + scale_size(to = c(0.1, 3))
> > # 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")
> > # See scale_date for examples of plotting multiple times series on > # a single graph
What do you think of the documentation? Please let me know by filling out this short online survey.