bee*_*oot 2 r ggplot2 direct-labels
我想使用包直接标签来标记我的情节.但是,我希望标签是每个点的ID.难道真的没有办法选择标注哪个因素或者我错过了哪个因素?
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)
Run Code Online (Sandbox Code Playgroud)
检查最后调用的direct.label.ggplot()节目代码geom_dl().该功能需要美学映射和定位方法.默认情况下使用的定位方法是返回值default.picker("ggplot"),它使用调用堆栈检查,在您的情况下等同于调用defaultpf.ggplot("point",,,).以下适用于我:
p1 <- ggplot(df, aes(x=value1, y=value2)) +
geom_point(aes(colour=group)) +
geom_dl(aes(label = id), method = defaultpf.ggplot("point",,,))
p1
Run Code Online (Sandbox Code Playgroud)
(请注意,您不再需要打电话direct.label().)
directlabels包裹的文件确实有点稀缺.