geom_text

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

Textual annotations

This page describes geom_text, 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_text. Aesthetics are mapped to variables in the data with the aes function: geom_text(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
labelrequired
colourblackbrewer, gradient, gradient2, gradientn, grey, hue, identity, manual
size5identity, manual, size
angle0
hjust0.5
vjust0.5
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.

Examples

> p <- ggplot(mtcars, aes(x=wt, y=mpg, label=rownames(mtcars))) 
>  
> p + geom_text() 
  
> p <- p + geom_point() 
>  
> # Set aesthetics to fixed value 
> p + geom_text() 
  
> p + geom_point() + geom_text(hjust=0, vjust=0) 
  
> p + geom_point() + geom_text(angle = 45) 
  
>  
> # Add aesthetic mappings 
> p + geom_text(aes(colour=factor(cyl))) 
  
> p + geom_text(aes(colour=factor(cyl))) + scale_colour_discrete(l=40) 
  
>  
> p + geom_text(aes(size=wt)) 
  
> p + geom_text(aes(size=wt)) + scale_size(to=c(3,6)) 
  
>  
> # Use qplot instead 
> qplot(wt, mpg, data = mtcars, label = rownames(mtcars), 
+    geom=c("point", "text")) 
  
> qplot(wt, mpg, data = mtcars, label = rownames(mtcars), size = wt) + 
+   geom_text(colour = "red") 
  

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