PlotEnrichDotPlot ggplot2画图拆解

# return heat colors of given length
GetMyHeatCols <- function(len){
  if(len > 50){
    ht.col <- c(substr(heat.colors(50), 0, 7), rep("#FFFFFF", len-50));
  }else{
    # reduce to hex by remove the last character so HTML understand
    ht.col <- substr(heat.colors(len), 0, 7);
  }
}





results <- mSet$analSet$ora.mat
my.cols <- GetMyHeatCols(nrow(results))

function (mSetObj = NA, enrichType = "ora", imgName, format = "png", 
          dpi = 72, width = NA) 

  {

  
  
  if ("ora" == "ora") {
    results <- mSet$analSet$ora.mat
    my.cols <- GetMyHeatCols(nrow(results))
    
    print(results)
    if (nrow(results) > 25) {
      results <- results[1:25, ]
      my.cols <- my.cols[1:25]
    }
    
    
    df <- data.frame(Name = factor(row.names(results), levels = rev(row.names(results))), 
                     rawp = results[, 4], logp = -log10(results[, 4]), 
                     folds = results[, 3]/results[, 2])
    print(df)
  }
  
 

 

PlotEnrichDotPlot ggplot2画图拆解_第1张图片


  
  maxp <- max(df$rawp)
  
  
   p <- ggplot(df, aes(x = logp, y = Name)) + geom_point(aes(size = folds, 
                                                            color = rawp)) + scale_size_continuous(range = c(2, 8)) + 
    theme_bw(base_size = 14.5) + scale_colour_gradient(limits = c(0, 
                                                                  maxp), low = my.cols[1], high = my.cols[length(my.cols)]) + 
    ylab(NULL) + xlab("-log10 (p-value)") + ggtitle("Overview of Enriched Metabolite Sets (Top 25)") + 
    theme(legend.text = element_text(size = 14), legend.title = element_text(size = 15))
  
   p$labels$colour <- "P-value"
  p$labels$size <- "Enrichment Ratio"
  ggsave(p, filename = imgName, dpi = dpi, width = w, height = h)

}

 PlotEnrichDotPlot ggplot2画图拆解_第2张图片

PlotEnrichDotPlot ggplot2画图拆解_第3张图片 

 

你可能感兴趣的:(r)