YSU

  •  
  • 2019年8月3日
  • 注册于 2010年9月17日
  • 效果图如上↑

    这个问题我之前也刚好需要到,试过几种姿势来完成任务。点少的话直接用geom_text即可,点多的话可以试试ggrepel包的geom_text_repel函数,代码:

    library(ggplot2)
    library(dplyr)
    library(ggrepel)
    
    ## example data
    uu <- data.frame(wz=rnorm(50,2),p=runif(50))
    
    
    gg <- ggplot(uu,aes(wz,p))+
      geom_point()+
      geom_point(data=uu %>% filter(wz >2),color="red")+
      geom_hline(yintercept=(-log10(0.01)))+
      theme_classic()+
    ## annotate points
      geom_text_repel(data=uu %>% filter(wz >2),aes(label=sprintf("%0.2f", round(wz, digits = 2))))
    
    print(gg)