我想使用軟件包的直接標籤來標記我的圖。不過,我希望標籤是每個點的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