I'd like to use the package directlabels to label my plot. However, I'd like the label to be the ID of each point. Is there really no way to select which factor to label or did I miss that?
library(ggplot2)
library(directlabels)
df <- structure(
list(id = 1:10,
group = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L),
.Label = c("A", "B"),
class = "factor"),
value1 = c(4, 1, 6, 2, 5, 7, 3, 2, 5, 8),
value2 = c(6, 2, 6, 2, 8, 9, 7, 5, 2, 6)
),
.Names = c("id", "group", "value1", "value2"),
row.names = c(NA, -10L),
class = "data.frame")
p1 <- ggplot(df, aes(x=value1, y=value2)) + geom_point(aes(colour=group))
direct.label(p1)
geom_text
? – Jaapdirect.label
is used as an alternative of the legends (i.e. it is used to show the groups in your graph) not as a way to add labels on each point. For point labels usegeom_text
as Jaap mentions in his comment. – LyzandeRgeom_text
a lot of the labels are overlapped – erc