我想使用软件包的直接标签来标记我的图。不过,我希望标签是每个点的ID。是否真的没有办法选择标注哪个因素或我错过了?选择标签的因子(ggplot2,directlabels)
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'? – Jaap
'direct.label'被用作图例的替代(即用于显示图形中的组),而不是在每个点上添加标签的方式。对于点标签,使用'geom_text'作为Jaap在他的评论中提到的内容。 – LyzandeR
@Jaap因为我的实际情节由大约200个点组成,而'geom_text'大量标签重叠 – beetroot