| geom_text {ggplot2} | R Documentation |
Textual annotations
geom_text(mapping = NULL, data = NULL, stat = "identity", position = "identity",
parse = FALSE, ...)
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 |
parse |
If TRUE, the labels will be parsed into expressions and displayed as described in ?plotmath |
... |
other arguments |
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(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
alpha: transparency
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))
# You can display expressions by setting parse = TRUE. The
# details of the display are described in ?plotmath, but note that
# geom_text uses strings, not expressions.
p + geom_text(aes(label = paste(wt, "^(", cyl, ")", sep = "")),
parse = T)
# 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")
## End(Not run)