I need to discuss a scatter plot and would like to refer to particular regions of the plot. Is there any way to 'highlight' particular sections of the plot? Perhaps with boxes and labels as below?
set.seed(1410)
dsmall<-diamonds[sample(nrow(diamonds), 100), ]
df<-data.frame("x"=dsmall$carat, "y"=dsmall$price)
p <-ggplot(df, aes(x, y))
p <- p + geom_point(alpha=2/10, shape=21, fill="blue", colour="black", size=5)
For a single region, it's easiest to use
annotate
, first withrect
, thentext
:For multiple regions, you can put the data into a data frame and use
geom_text
andgeom_rect
: