r - 标签、数据点等的重叠绘制(w geom_dl 和直接标签)

标签 r ggplot2 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 中自己重新排列它们?

Producing this plot

非常感谢您的投入!

最佳答案

我不熟悉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

关于r - 标签、数据点等的重叠绘制(w geom_dl 和直接标签),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29904525/

相关文章:

r - 传单绘图工具栏 : allow only editing and deleting but not adding new markers in R Shiny

r - 将 filter(across()) 语句与 | 链接起来(OR) 而不是 & (AND)

r - 使用填充美学两次,具有两种不同的比例

javascript - 如何根据组合框选择更改文本标签?

javascript - D3 圆包布局中沿圆圈的文本

r - ggplot2 轴文本中的上标

r - xts 对象中每月的第 N 天

r - 如何在R中绘制条形图的次轴?

r - 使用 ggplot2 更改单个图形刻度线的位置

javascript - 使用 D3.js 在文本值之间转换