Selecting factor for labels (ggplot2, directlabels)

╄→гoц情女王★ 提交于 2019-12-04 16:41:18

Inspecting the code of direct.label.ggplot() shows that geom_dl() is called in the end. This function expects an aesthetic mapping and a positioning method. The positioning method used by default is the return value of default.picker("ggplot"), which uses call stack examination and in your case is equivalent to calling defaultpf.ggplot("point",,,). The following works for me:

p1 <- ggplot(df, aes(x=value1, y=value2)) +
  geom_point(aes(colour=group)) +
  geom_dl(aes(label = id), method = defaultpf.ggplot("point",,,))
p1

(Note that you don't need to call direct.label() anymore.)

The documentation of the directlabels package is indeed a bit scarce.

You have to write a custom position method, like so:

label_all <- list( dl.trans(x = x + 0.5, y = y + 0.5), # shift every point up and right
                   gapply.fun(d) ) # include all points
direct.label(p1, method = label_all)

For another example, see the documentation, under "Specifying the positioning method as a list".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!