Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use annotate() and a text geom (Figure 7-1):
p<-ggplot(faithful,aes(x=eruptions,y=waiting))+geom_point()p+annotate("text",x=3,y=48,label="Group 1")+annotate("text",x=4.5,y=66,label="Group 2")
The annotate() function can
be used to add any type of geometric object. In this case, we used
geom="text".
Other text properties can be specified, as shown in Figure 7-2:
p+annotate("text",x=3,y=48,label="Group 1",family="serif",fontface="italic",colour="darkred",size=3)+annotate("text",x=4.5,y=66,label="Group 2",family="serif",fontface="italic",colour="darkred",size=3)