R/geneticqgraph-plot.R

Defines functions genericqgraph

Documented in genericqgraph

#'  qgraph plot
#'
#'
#' @param tmpCor  correlation matrix
#'
#' @examples
#'  data(corrplot_data)
#'  metaname <-names(corrplot_data)
#'  tmpDataset <- as.matrix(corrplot_data);
#   #handle pathway info
#'
#'  set.seed(1)
#'  Pathway <- sort(paste0("p",as.integer(runif(length(metaname), 0, 1)*3+1)))
#'  step 3, handle pathway info
#'  pathwayData <- data.frame(Var= (metaname),
#'                            Pathway = ((Pathway)))
#'  # generate suitable group index
#'  qgraph_path <- pathwayData[with(pathwayData, order(Pathway)), ] # sort data frame by column Pathway
#'  qgraph_path$Var <- as.character(qgraph_path$Var)
#'  tmp <- tmpDataset[,c(qgraph_path$Var)] # select pathway subset according to sorted order
#'  qgraph_groups <- as.character(qgraph_path$Pathway); # generate group index
#'  sample_size <- nrow(tmp)
#'  tmpCor <- cor(tmp, use ="pairwise.complete.obs" ,method="pearson");
#'  genericqgraph(tmpCor,groups=qgraph_groups,graph = "pcor",
#'                sampleSize=sample_size,title=paste(sub_time,gen,"partial corre"),
#'                threshold = "BH",minimum  = "sig",
#'  );
#' @details  Please see \link[qgraph]{qgraph}
#'
#' @name genericqgraph
#' @rdname genericqgraph
#' @export
#'


genericqgraph <- function(tmpCor,
                          titleName = "",
                          labels = colnames(tmpCor), # adjust abbreviation or full name
                          esize = 20,alpha = 0.05,
                          cut  = NULL,maximum = 1,palette = "pastel",
                          posCol = "red",negCol = "blue",
                          details = TRUE,
                          layout = "spring",
                          label.cex = 0.9,label.prop = 0.9,
                          label.fill.horizontal = 1,shape = "ellipse"
                          ,...)
{
    col_fun = circlize::colorRamp2(c(-1, 1), c("blue", "red"), transparency = 0.1)
    # calculating the qgraph for the correlation matrix
    # plotting actual graph
    tmpQgraph <- qgraph::qgraph(tmpCor,
                                labels = colnames(tmpCor),
                                layout = layout,
                                esize = esize,
                                alpha = alpha,
                                cut = cut,
                                palette = palette,
                                posCol = posCol,
                                negCol = negCol,
                                details = details,
                                label.cex = label.cex,
                                label.prop = label.prop,
                                label.fill.horizontal = label.fill.horizontal,
                                shape = shape
                                ,...
    )

    graphics::title(titleName, line = 2.5)
    return(tmpQgraph)
}
ShouyeLiu/metaboliteUtility documentation built on May 6, 2019, 9:07 a.m.