| geom_text {ggplot2} | R Documentation |
Textual annotations
geom_text(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_text, see layer and qplot for how to create a complete plot from individual components.
A layer
The following aesthetics can be used with geom_text. Aesthetics are mapped to variables in the data with the aes function: geom\_text(\code{aes}(x = var))
x: x position (required)
y: y position (required)
label: text label (required)
colour: border colour
size: size
angle: angle
hjust: horizontal justification, between 0 and 1
vjust: vertical justification, between 0 and 1
Hadley Wickham, http://had.co.nz/
## Not run:
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), geom=c("point","text"), size=wt)
## End(Not run)