Skip to content

Instantly share code, notes, and snippets.

@aaronsaunders
Created August 16, 2013 04:07
Show Gist options
  • Save aaronsaunders/6247227 to your computer and use it in GitHub Desktop.
Save aaronsaunders/6247227 to your computer and use it in GitHub Desktop.
dat <- data.frame(x = rnorm(10), y = rnorm(10), label = letters[1:10])
#Create a subset of data that you want to label. Here we label points a - e
labeled.dat <- dat[dat$label %in% letters[1:5] ,]
ggplot(dat, aes(x,y)) + geom_point() +
geom_text(data = labeled.dat, aes(x,y, label = label), hjust = 2)
#Or add a separate layer for each point you want to label.
ggplot(dat, aes(x,y)) + geom_point() +
geom_text(data = dat[dat$label == "c" ,], aes(x,y, label = label), hjust = 2) +
geom_text(data = dat[dat$label == "g" ,], aes(x,y, label = label), hjust = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment