geom_path

geom_path(mapping=NULL, data=NULL, stat="identity", position="identity", ...)

Connect observations, in original order

This page describes geom_path, 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.

Aesthetics

The following aesthetics can be used with geom_path. Aesthetics are mapped to variables in the data with the aes function: geom_path(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
xrequiredcontinuous, date, datetime, discrete
yrequiredcontinuous, date, datetime, discrete
colourblackbrewer, gradient, gradient2, gradientn, grey, hue, identity, manual
size0.5identity, manual, size
linetype1identity, linetype, manual
alpha1

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

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.

Returns

This function returns a layer object.

See also

Examples

> # Generate data 
> myear <- ddply(movies, .(year), colwise(mean, .(length, rating))) 
> p <- ggplot(myear, aes(length, 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") 
Error: object 'mean.length' not found
  
>  
> # 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) 
Error: geom_path: If you are using dotted or dashed lines, colour, size and linetype must be constant over the line
  

What do you think of the documentation? Please let me know by filling out this short online survey.