stat_quantile

stat_quantile(mapping=NULL, data=NULL, geom="quantile", position="identity", quantiles=c(0.25, 0.5, 0.75), formula=y ~ x, method="rq", na.rm=FALSE, ...)

Continuous quantiles

This page describes stat_quantile, 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 stat_quantile. Aesthetics are mapped to variables in the data with the aes function: stat_quantile(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
group..quantile..

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.

New variables produced by the statistic

To use these variables in an aesthetic mapping, you need to surrond them with .., like aes(x = ..output..). This tells ggplot that the variable isn't the original dataset, but has been created by the statistic.

Parameters

Parameters control the appearance of the stat. 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.

Examples

> msamp <- movies[sample(nrow(movies), 1000), ] 
> m <- ggplot(msamp, aes(y=rating, x=year)) + geom_point() 
> m + stat_quantile() 
  
> m + stat_quantile(quantiles = 0.5) 
  
> m + stat_quantile(quantiles = seq(0.1, 0.9, by=0.1)) 
Warning: Solution may be nonunique
  
>  
> # Doesn't work.  Not sure why. 
> # m + stat_quantile(method = rqss, formula = y ~ qss(x), quantiles = 0.5) 
>  
> # Add aesthetic mappings 
> m + stat_quantile(aes(weight=votes)) 
  
>  
> # Change scale 
> m + stat_quantile(aes(colour = ..quantile..), quantiles = seq(0.05, 0.95, by=0. 
+ 05)) 
Warning: Solution may be nonunique
  
> m + stat_quantile(aes(colour = ..quantile..), quantiles = seq(0.05, 0.95, by=0. 
+ 05)) + 
+   scale_colour_gradient2(midpoint=0.5, low="green", mid="yellow", high="green") 
Warning: Solution may be nonunique
  
>  
> # Set aesthetics to fixed value 
> m + stat_quantile(colour="red", size=2, linetype=2) 
  
>  
> # Use qplot instead 
> qplot(year, rating, data=movies, geom="quantile") 
  

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