~ubuntu-branches/ubuntu/utopic/r-bioc-cummerbund/utopic

« back to all changes in this revision

Viewing changes to R/tools.R

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2013-12-28 17:17:25 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131228171725-polmzo8go4m371c6
Tags: 2.4.1-1
* New upstream version
* debian/rules: Remove useless creation of ${R-Depends}
* debian/control: Versioned Build-Depends: r-base-dev (>= 3.0)
* debian/README.test: add hint how to test the package

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
        b
62
62
}
63
63
 
 
64
.plotmatrix <- function (data, hexbin=FALSE, mapping = aes())
 
65
#Modified from original ggplot2 plotmatrix
 
66
{
 
67
        grid <- expand.grid(x = 1:ncol(data), y = 1:ncol(data))
 
68
        grid <- subset(grid, x != y)
 
69
        all <- do.call("rbind", lapply(1:nrow(grid), function(i) {
 
70
                                                xcol <- grid[i, "x"]
 
71
                                                ycol <- grid[i, "y"]
 
72
                                                data.frame(xvar = names(data)[ycol], yvar = names(data)[xcol], 
 
73
                                                                x = data[, xcol], y = data[, ycol], data)
 
74
                                        }))
 
75
        all$xvar <- factor(all$xvar, levels = names(data))
 
76
        all$yvar <- factor(all$yvar, levels = names(data))
 
77
        densities <- do.call("rbind", lapply(1:ncol(data), function(i) {
 
78
                                                data.frame(xvar = names(data)[i], yvar = names(data)[i], 
 
79
                                                                x = data[, i])
 
80
                                        }))
 
81
        mapping <- plyr::defaults(mapping, aes_string(x = "x", y = "y"))
 
82
        class(mapping) <- "uneval"
 
83
        p <-ggplot(all) + facet_grid(xvar ~ yvar)#, scales = "free")
 
84
        
 
85
        if(hexbin){ 
 
86
                p<- p + geom_hex(mapping,size=1.5,na.rm = TRUE) 
 
87
        }else{
 
88
                p<- p + geom_point(mapping,alpha=0.2,size=0.8,na.rm=TRUE)
 
89
        }
 
90
        
 
91
        p<- p + stat_density(aes(x = x, 
 
92
                                        y = ..scaled.. * diff(range(x)) + min(x)), data = densities, 
 
93
                        position = "identity", colour = "grey20", geom = "line")
 
94
        
 
95
        p
 
96
}
 
97
 
 
98
#.volcanoMatrix <- function(data){
 
99
#       part1<-data[,c('gene_id','sample_1','sample_2','value_1','value_2','test_stat','p_value','q_value')]
 
100
#       part2<-data.frame(gene_id=part1$gene_id,sample_1=part1$sample_2,sample_2=part1$sample_1,value_1=part1$value_2,value_2=part1$value_1,test_stat=-part1$test_stat,p_value=part1$p_value,q_value=part1$q_value)
 
101
#       data<-rbind(part1,part2)
 
102
#       myLevels<-union(data$sample_1,data$sample_2)
 
103
#       data$sample_1<-factor(data$sample_1,levels=myLevels)
 
104
#       data$sample_2<-factor(data$sample_2,levels=myLevels)
 
105
#       data$log2_fold_change<-log2(data$value_2/data$value_1)
 
106
#       filler<-data.frame(sample_1=factor(myLevels,levels=myLevels),sample_2=factor(myLevels,levels=myLevels),label=as.character(myLevels))
 
107
#       filler$label<-as.character(filler$label)
 
108
#       mapping <- defaults(mapping, aes_string(x = "log2_fold_change", y = "-log10(p_value)"))
 
109
#       class(mapping) <- "uneval"
 
110
#       
 
111
#       p <-ggplot(data) + geom_point(mapping,na.rm=TRUE,size=0.8) + geom_text(aes(x=0,y=15,label=label),data=filler) + facet_grid(sample_1~sample_2)
 
112
#       
 
113
#       p
 
114
#       
 
115
#}
 
116
 
64
117
#multiplot <- function(..., plotlist=NULL, cols) {
65
118
#       require(grid)
66
119
#