R/manhattan_plot.R

#' manhattan_plot
#' @param result a result data.frame from a compute_phewas function
#' @param type a type of result in c('concepts', 'bio','cim')
#' @return manhattan plot 
#' @export
manhattan_plot <- function(result, type = 'concepts') {
  require(ggplot2, quietly = TRUE)
  
  if(is.null(result$CAT)) return( ggplot(data.frame(x=0,y=0)) + theme_void())
  
  result <- dplyr::mutate(result, CAT = stringr::str_sub(result$CAT, 1, 50))
  
  if (type == 'concepts') {
    p <- ggplot(result, aes(y= CAT, 
                            x = -log10(p_bonf), 
                            color= CAT,
                            label= CODE_LABEL,
                            text = paste0("odds-ratio: ",round(OR,1), ' [',round(CI_inf,1),'-',round(CI_sup,1),']'))) +
      geom_vline(label = 'Bonferroni Threshold', xintercept = -log10(0.05), linetype = 3) +
      geom_jitter(size = 3, alpha = 0.5) +
      theme_minimal() +
      ylab('Phenotypes') +
      xlab('-log(p)') +
      #  ggtitle(paste(snp_sel,' - ', gene_sel)) +
      theme(legend.position="none") 
  } else if (type == 'bio')
    
    p <- ggplot(result, aes(y= CAT, 
                            x = -log10(p_bonf), 
                            color= CAT,
                            fill= CAT,
                            label= CODE_LABEL,
                            shape = direction,
                            text = paste0("odds-ratio: ",round(OR,1), ' [',round(CI_inf,1),'-',round(CI_sup,1),']'))) +
      scale_shape_manual(values=c(25,24)) +
      geom_vline(label = 'Bonferroni Threshold', xintercept = -log10(0.05), linetype = 3) +
      geom_jitter(size = 3, alpha = 0.5) +
      theme_minimal() +
      ylab('Phenotypes') +
      xlab('-log(p)') +
      #  ggtitle(paste(snp_sel,' - ', gene_sel)) +
      theme(legend.position="none") 
  
  else if (type == 'cim') {
    p <- ggplot(result, aes(y= CAT, 
                            x = -log10(p_bonf), 
                            color= CAT,
                            fill= CAT,
                            label= CODE_LABEL,
                            text = paste0("odds-ratio: ",round(OR,1), ' [',round(CI_inf,1),'-',round(CI_sup,1),']'))) +
      geom_vline(label = 'Bonferroni Threshold', xintercept = -log10(0.05), linetype = 3) +
      geom_jitter(size = 3, alpha = 0.5) +
      theme_minimal() +
      ylab('Phenotypes') +
      xlab('-log(p)') +
      #  ggtitle(paste(snp_sel,' - ', gene_sel)) +
      theme(legend.position="none") 
  }
  p
  
}
aneuraz/multiWAS documentation built on May 14, 2019, 2:37 p.m.