-
Notifications
You must be signed in to change notification settings - Fork 9
MetQy functions and usage examples – Visualisation functions
Andrea Martinez Vernon edited this page Aug 4, 2018
·
4 revisions
The visualisation family of functions is designed to facilitate the analysis primarily of the output of the query_genomes_to_modules function, which generates a matrix of mcf values for the genomes and modules analysed.
MetQy features five visualisation functions:
See below for example code.
Note that the function analysis_genomes_module_output processes the output from query_genomes_to_modules and uses all visualisation functions (except plot_sunburst).
Function useful to visualise the output from query_genomes_to_modules.
> data(data_example_moduleIDs)
> data(data_example_genomeIDs)
# Calculate the module completion fraction (mcf) for the genomes and modules contained in the data objects above.
> OUT <- query_genomes_to_modules(data_example_genomeIDs,MODULE_ID = data_example_moduleIDs)
# Make a heatmap of the mcf output from query_genomes_to_modules.
> p <- plot_heatmap(OUT$MATRIX,ORDER_MATRIX = F,Filename = "plot_heatmap.png")
# Reorder rows and columns according to the dendrogram resulting from hierarchical clustering (same data).
p <- plot_heatmap(OUT$MATRIX,ORDER_MATRIX = T,Filename = "plot_heatmap_ordered.png")
Function useful to visualise a scatter plot made of categorical or string variables associated with numeric values.
> plot_data_example <- data.frame("Groups"=LETTERS[1:12],
"Factor"=c(rep(1,4),rep(2,4),rep(3,4)),
"Value"=runif(12,-10,10),stringsAsFactors = FALSE)
> p1 <- plot_scatter(plot_data_example,Filename = "plot_scatter.png",Width = 4,Height = 3)
# Separate based on the "Factor" column
> p2 <- plot_scatter(plot_data_example,colBy = 2,Filename = "plot_scatter_colBy.png",Width = 4,Height = 3)
# Change plot order to be according to the numeric value
> plot_data_example_ordered <- plot_data_example[order(plot_data_example$Value),]
> p3 <- plot_scatter(plot_data_example_ordered,Filename = "plot_scatter_ordered.png",Width = 4,Height = 3)
> data(data_example_moduleIDs)
> data(data_example_genomeIDs)
# length(data_example_genomeIDs) # [1] 25
# Calculate the module completion fraction (mcf) for the genomes and modules contained in the data objects above.
> OUT <- query_genomes_to_modules(data_example_genomeIDs,MODULE_ID = data_example_moduleIDs)
# GET PCA
> pca <- prcomp(OUT$MATRIX)
# Make boxplots of the mcf output from query_genomes_to_modules
> this_FACTOR <- rep(LETTERS[1:5],length(data_example_genomeIDs)/5)
> plot_output <- plot_scatter_byFactors(pca$x[,1:2],FACTOR = this_FACTOR,factor_labs = "random",Filename = "plot_scatter_byFactors.png")
# NAs are ommitted, so a single group can be contrasted with overall data
this_FACTOR <- c(rep(NA,20),rep(LETTERS[1],5))
plot_output <- plot_scatter_byFactors(pca$x[,1:2],FACTOR = this_FACTOR,factor_labs = "group_A",Filename = "plot_scatter_byFactors_single.png")
Function useful to visualise the output from query_genomes_to_modules.
> library(MetQy)
> data(data_example_sunburst)
> data(data_example_sunburst_fill_by)
# Simplest plot using count data (WIDTH scales text size)
> plot_data <- plot_sunburst(sunbust_data,WIDTH = 8,HEIGHT = 8,Filename = "plot_sunburst.png")
# Specify values to be used for outer ring (lowest level) and change legend name accordingly
> plot_data <- plot_sunburst(data_example_sunburst,centerLabel = "Org A",fill_by = data_example_sunburst_fill_by, legend_name = "fill_by",WIDTH = 8,HEIGHT = 8,Filename = "plot_sunburst_fill_by.pdf")
# Also fill inner rings (levels) according to the mean values determined by fill_by.
> plot_data <- plot_sunburst(data_example_sunburst,centerLabel = "Org A",fill_by = data_example_sunburst_fill_by,fill_by_mean = T, legend_name = "fill_by",WIDTH = 8,HEIGHT = 8,Filename = "plot_sunburst_fill_by_mean.pdf")
# Retrieve example data
> data(data_example_moduleIDs)
> data(data_example_genomeIDs)
# Calculate the module completion fraction (mcf) for the genomes and modules contained in the data objects above.
> OUT <- query_genomes_to_modules(data_example_genomeIDs,MODULE_ID = data_example_moduleIDs)
# Make boxplots of the mcf output from query_genomes_to_modules
> p <- plot_variance_boxplot(OUT$MATRIX,xLabs_angle = F,Filename = "plot_variance_boxplot.png",Width = 4,Height = 2)