Textual annotations
The following aesthetics can be used with geom_text. They are listed along with their default value. All geoms and scales can also use the group aesthetic. Read how this important aesthetic works in scale_group. Typically, you will associate an aesthetic with a variable in your data set. To do this, you use the aes function: geom_text(aes(x = var))
. Scales control the details of the mapping between data and aesthetic properties; after each aesthetic are listed scales that can be used with that aesthetic. The scale documentation will also provide references to help you interpret the default values.
Instead of mapping an aesthetic to a variable in your dataset, you can also set it to a fixed value. See the parameters section for details.
label:
colour: black
(scales: brewer, gradient, gradient2, hue, manual)
size: 1
(scales: area, manual, size, size_discrete)
angle: 0
hjust: 0.5
vjust: 0.5
When an aesthetic is used an a parameter, like geom_text(label = 3)
, it will override mappings from data.
label
, text labelcolour
, border coloursize
, sizeangle
, anglehjust
, horizontal justification, between 0 and 1vjust
, vertical justification, between 0 and 1stat_identity. Override with the stat
argument: geom_text(stat="identity")
position_identity. Override with the position
argument: geom_text(position="jitter")
.
> 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 for continuous variable'>scale_size(to=c(0.5,1.5))
> > # 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)
![]()