在x,y散点图中使用DirectLabel

在x,y散点图中使用DirectLabel,r,ggplot2,R,Ggplot2,我很难找到在x,y散点图中使用DirectLabel的最佳方法 library(ggplot2) library(directlabels) p1 <- ggplot()+ geom_point(data=sites, aes(X, Y, col=Treatment), alpha=1,show_guide=FALSE) + geom_polygon(data = hulls, aes(X, Y, colour=Treatment, fill=Treatme

我很难找到在x,y散点图中使用DirectLabel的最佳方法

library(ggplot2)
library(directlabels)
p1 <- ggplot()+
        geom_point(data=sites, aes(X, Y, col=Treatment), alpha=1,show_guide=FALSE) +
        geom_polygon(data = hulls, aes(X, Y, colour=Treatment, fill=Treatment), lty="dashed", alpha = 0.1, show_guide=FALSE) +
        theme_bw() +
        #geom_text(data=sites, aes(X,Y, label=Sample, color=Treatment), size=2, show_guide=FALSE) +
        theme(axis.line = element_line(colour = "black"),
              panel.grid.major = element_blank(),
              panel.grid.minor = element_blank(),
              #panel.border = element_blank(),
              panel.background = element_blank()) +
        coord_fixed() +
        annotate("text", x=-0.8, y=-0.55, label="Stress = 0.102")

p2 <- p1 +  geom_dl(data=sites, aes(X,Y,label=Sample, colour=Treatment, list( cex = 0.6)), method="smart.grid", show_guide=FALSE)
p2
库(ggplot2)
库(directlabels)

p1directlabels并不真正用于标记散点图上的单个点(这是NP难的)

也就是说,您可能希望尝试编写自己的定位方法:

your.method <- function(point.df, ...){
  print(point.df)
  browser()
  label.df <- your_label_computation_function(point.df) 
  label.df
}
p2 <- p1 +  geom_dl(data=sites, aes(X,Y,label=Sample, colour=Treatment, list( cex = 0.6)), method="your.method", show_guide=FALSE)

your.method我不再考虑这种问题,因为我从来没有得到一个好的工作解决方案。我的解决方案是对图形感到满意,或者如果我需要它作为出版物,我只需使用pdf/svg文件和@illustrator或inkscape,并将标签移动到最佳位置。同样,我没有足够的耐心:-)这就是我删除评论的原因。
your.method <- function(point.df, ...){
  print(point.df)
  browser()
  label.df <- your_label_computation_function(point.df) 
  label.df
}
p2 <- p1 +  geom_dl(data=sites, aes(X,Y,label=Sample, colour=Treatment, list( cex = 0.6)), method="your.method", show_guide=FALSE)