标签、数据点等的过度绘制(w geom_dl & 直接标签)

Overplotting of labels, data points and more (w geom_dl & direct label)

我找不到解决我的重叠问题的方法。如果有人可以帮助我找到解决方案,我将不胜感激。

我的数据如下所示(csv 格式):http://pastebin.com/embed_js.php?i=Cnfpkjsz

这是我的代码 运行:

     library(dplyr)
    library(gdata)
    library(ggplot2)
    library(directlabels)


    all<-read.xls('all_auto_bio_adjusted.xls')

    all$station<-as.factor(all$station)
    all$automatic<-log(all$automatic)
    all$averagebiol<-log(all$averagebiol)
    all$stdevbiol<-log(all$stdevbiol)

    pd <- position_dodge(.9) 

    allp<-ggplot(data=all, aes(y=averagebiol, x=automatic, colour=group)) +
      geom_errorbar(aes(ymin=averagebiol-stdevbiol, ymax=averagebiol+stdevbiol), colour="red", width=.1, position=pd) +
      geom_point(aes(size=size), show_guide = TRUE) +
      geom_abline(intercept=0, slope=1) +
      stat_smooth(method="loess",se=FALSE,colour='blue') +
      geom_dl(aes(label=shortname),method="last.bumpup",cex = 1.3, hjust = 1) +
      facet_wrap(~station,nrow=2)+
      xlab("auto")  +
      ylab("manual") +
      ggtitle("Comparison of automatic vs manual identification") +
      scale_y_continuous(limits=c(0, max(all$averagebiol + all$stdevbiol))) +
      theme_bw() +
      theme(plot.title = element_text(lineheight=.8, face="bold", size=20,vjust=1), axis.text.x = element_text(colour="grey20",size=15,angle=0,hjust=.5,vjust=.5,face="bold"), axis.text.y = element_text(colour="grey20",size=15,angle=0,hjust=1,vjust=0,face="bold"),  axis.title.x = element_text(colour="grey20",size=20,angle=0,hjust=.5,vjust=0,face="bold"), axis.title.y = element_text(colour="grey20",size=20,angle=90,hjust=.5,vjust=1,face="bold"),legend.position="right")

allp

我尝试了很多不同的 geom_dl 方法,但找不到合适的方法。有没有可以在误差线上方绘制的?

如果没有适合我的。我该怎么做才能至少将标签绘制得很好,以便我可以自己在 photoshop 中重新排列它们?

非常感谢您的意见!

我不熟悉 directlabels 但是如果你想将标签移到顶部你可以用 geom_text():

allp <- ggplot(data = all, aes(y = averagebiol, x = automatic, colour = group)) + 
  geom_errorbar(aes(ymin = averagebiol - stdevbiol, ymax = averagebiol + stdevbiol),
                colour = "red", width = 0.1, position = pd) +
  geom_point(aes(size = size), show_guide = TRUE) +
  geom_abline(intercept = 0, slope = 1) +
  stat_smooth(method = "loess", se = FALSE, colour = "blue") +
  facet_wrap(~station, nrow = 2) +
  xlab("auto") + ylab("manual") +
  ggtitle("Comparison of automatic vs manual identification") + 
  scale_y_continuous(limits = c(0, max(all$averagebiol + all$stdevbiol)))

allp + geom_text(aes(label = shortname, y = averagebiol + stdevbiol), vjust = -0.1) 

不过似乎还是太忙了,没时间区分组别。跳过文本标签并在 stationgroup 上分面怎么样?这是一个可能的开始,如果你喜欢它,你需要调整它...

allp <- ggplot(data = all, aes(y = averagebiol, x = automatic, colour = group)) + 
  geom_errorbar(aes(ymin = averagebiol - stdevbiol, ymax = averagebiol + stdevbiol),
                colour = "grey", width = 0.5, position = pd) +
  geom_point(aes(size = size), show_guide = TRUE) +
  geom_abline(intercept = 0, slope = 1) +
  stat_smooth(method = "loess", se = FALSE, colour = "blue") +
  facet_grid(station ~ group) +
  xlab("auto") + ylab("manual") +
  ggtitle("Comparison of automatic vs manual identification") + 
  scale_y_continuous(limits = c(0, max(all$averagebiol + all$stdevbiol))) +
  theme_minimal()

allp

我希望你想要这样的东西。

我的代码:

allp<-ggplot(data=all, aes(y=averagebiol, x=automatic, colour=group)) +
  geom_point(aes(size=size), show_guide = TRUE) +
  geom_abline(intercept=0, slope=1) +
  stat_smooth(method="loess",se=FALSE,colour='blue') +
  facet_wrap(~station,nrow=2)+
  xlab("auto")  +
  ylab("manual") +
  ggtitle("Comparison of automatic vs manual identification") +
  scale_y_continuous(limits=c(0, max(all$averagebiol + all$stdevbiol + 1, na.rm=T))) +
  theme_bw() +
  theme(plot.title = element_text(lineheight=.8, face="bold", size=20,vjust=1), axis.text.x = element_text(colour="grey20",size=15,angle=0,hjust=.5,vjust=.5,face="bold"), axis.text.y = element_text(colour="grey20",size=15,angle=0,hjust=1,vjust=0,face="bold"),  axis.title.x = element_text(colour="grey20",size=20,angle=0,hjust=.5,vjust=0,face="bold"), axis.title.y = element_text(colour="grey20",size=20,angle=90,hjust=.5,vjust=1,face="bold"),legend.position="right")+
  geom_errorbar(aes(ymin=averagebiol-stdevbiol, ymax=averagebiol+stdevbiol), colour="red", width=.1, position=pd) +
  geom_text(aes(label = shortname, y = averagebiol+stdevbiol), vjust = -.3) 

我删除了您的标签代码行,并引入了这一行:

  geom_text(aes(label = shortname, y = averagebiol+stdevbiol), vjust = -.3) 

这只是将标签放在错误栏的顶部,稍作调整。

我也修改了这部分:

scale_y_continuous(limits=c(0, max(all$averagebiol + all$stdevbiol + 1, na.rm=T)))

标签在上面,一些标签被灰色条覆盖,所以我增加了一点 X 条的值 (+1),但最大值不起作用加上我的一点点就正确了,所以我不得不删除 NA 值。

事实上,在 Harrop 的输入后,我最终按站和组分面。

这是我的代码(基础数据略有变化)

library(dplyr)
library(gdata)
library(ggplot2)
library(directlabels)


all<-read.xls('all_auto_bio_adjusted_c.xls')
all$size.new<-sqrt(all$size.new)
all$station<-as.factor(all$station)
all$group.new<-factor(all$group, levels=c('C. hyperboreus','C. glacialis','Special Calanus','M. longa','Pseudocalanus sp.','Copepoda'))

pd <- position_dodge(w = 50) 

allp <- ggplot(data = all, aes(y = averagebiol, x = automatic, colour = group.new, group=group.new)) + 
  geom_abline(intercept = 0, slope = 1) +
  geom_point(aes(size = size.new), show_guide=TRUE, position=pd) +
  scale_size_identity()+
  geom_errorbar(aes(ymin = averagebiol - stdevbiol, ymax = averagebiol +   stdevbiol),colour = "grey", width = 0.1, position=pd) +
  facet_grid(group.new~station, scales="free") +
  xlab("Automatic identification") + ylab("Manual identification") +
  ggtitle("Comparison of automatic vs manual identification") + 
  theme_bw() + 
  theme(plot.title = element_text(lineheight=.8, face="bold", size=20,vjust=1), axis.text.x = element_text(colour="grey20",size=15,angle=0,hjust=.5,vjust=.5,face="bold"), axis.text.y = element_text(colour="grey20",size=15,angle=0,hjust=1,vjust=0,face="bold"),  axis.title.x = element_text(colour="grey20",size=20,angle=0,hjust=.5,vjust=0,face="bold"), axis.title.y = element_text(colour="grey20",size=20,angle=90,hjust=.5,vjust=1,face="bold"), legend.position="none", strip.text.x = element_text(size = 12, face="bold", colour = "black", angle = 0), strip.text.y = element_text(size = 12, face="bold", colour = "black"))

allp