| geom_path {ggplot2} | R Documentation |
Connect observations, in original order
geom_path(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_path, see layer and qplot for how to create a complete plot from individual components.
A layer
The following aesthetics can be used with geom_path. Aesthetics are mapped to variables in the data with the aes function: geom\_path(\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_line: Functional (ordered) lines
geom_polygon: Filled paths (polygons)
geom_segment: Line segments
## Not run:
# Generate data
myear <- do.call(rbind, by(movies, movies$year, function(df) data.frame(year=df$year[1], mean.length = mean(df$length), mean.rating=mean(df$rating))))
p <- ggplot(myear, aes(x=mean.length, y=mean.rating))
p + geom_path()
# Add aesthetic mappings
p + geom_path(aes(size=year))
p + geom_path(aes(colour=year))
# Change scale
p + geom_path(aes(size=year)) + scale_size(to=c(1, 3))
# Set aesthetics to fixed value
p + geom_path(colour = "green")
# Use qplot instead
qplot(mean.length, mean.rating, data=myear, geom="path")
# Using economic data:
# How is unemployment and personal savings rate related?
qplot(unemploy/pop, psavert, data=economics)
qplot(unemploy/pop, psavert, data=economics, geom="path")
qplot(unemploy/pop, psavert, data=economics, geom="path", size=as.numeric(date))
# How is rate of unemployment and length of unemployment?
qplot(unemploy/pop, uempmed, data=economics)
qplot(unemploy/pop, uempmed, data=economics, geom="path")
qplot(unemploy/pop, uempmed, data=economics, geom="path") +
geom_point(data=head(economics, 1), colour="red") +
geom_point(data=tail(economics, 1), colour="blue")
qplot(unemploy/pop, uempmed, data=economics, geom="path") +
geom_text(data=head(economics, 1), label="1967", colour="blue") +
geom_text(data=tail(economics, 1), label="2007", colour="blue")
# Setting line type vs colour/size
# Line type needs to be applied to a line as a whole, so it can
# not be used with colour or size that vary across a line
x <- seq(0.01, .99, length=100)
df <- data.frame(x = rep(x, 2), y = c(qlogis(x), 2 * qlogis(x)), group = rep(c("a","b"), each=100))
p <- ggplot(df, aes(x=x, y=y, group=group))
# Should work
p + geom_line(linetype = 2)
p + geom_line(aes(colour = group), linetype = 2)
p + geom_line(aes(colour = x))
# Should fail
p + geom_line(aes(colour = x), linetype=2)
## End(Not run)