• ggplot画图-分页and排序


    1. 输入数据

    2. Rscript

    #读取数据
    a<-read.table("../data/All.lib.list.modified.ref.hits.data1",header = T) 
    
    ##对分类进行排序
    a$ref=factor(a$ref,levels = c("ref1","ref2","ref3","ref4","ref5","ref6","ref7","ref8","ref9","ref10")) 
    
    ##建立每个分面的R<sup>2</sup>值和p-value值
    lm_labels<-function(dat){
      tmp = cor.test(dat$Rnum,dat$hits,method="pearson")
      r<-sprintf("italic(R^2)==%.3f", tmp$estimate)
      p<-sprintf("italic(p-vaule)==%.3f",tmp$p.value)
      data.frame(r=r,p=p,stringsAsFators=FALSE)
    }
    library(plyr)
    labels<-ddply(a,"ref",lm_labels)
    
    ##使用ggplot画图
    library(ggplot2)
    p<-ggplot(data=a,aes(x=Rnum/1000000,y=hits,color=ref))+
      geom_point()+stat_smooth()+
      theme(axis.text.x=element_text(size=8,vjust=1,hjust=1,angle=45))+
      facet_wrap(.~ref,nrow=2)+
      scale_x_continuous(breaks=seq(100,1500, 100))+
      geom_text(x=300,y=500,aes(label=r),data=labels,parse=TRUE)+
      geom_text(x=300,y=450,aes(label=p),data=labels,parse=TRUE)
    p
    
    1. 输出的结果
  • 相关阅读:
    函数式宏定义与普通函数
    linux之sort用法
    HDU 4390 Number Sequence 容斥原理
    HDU 4407 Sum 容斥原理
    HDU 4059 The Boss on Mars 容斥原理
    UVA12653 Buses
    UVA 12651 Triangles
    UVA 10892
    HDU 4292 Food
    HDU 4288 Coder
  • 原文地址:https://www.cnblogs.com/RyannBio/p/10717777.html
Copyright © 2020-2023  润新知