Learn R Programming

GSNA (version 0.1.4.2)

plot.GSNData: plot plot.GSNData

Description

Plot method for the networks within GSNData objects, implemented with gsnPlotNetwork.

Usage

# S3 method for GSNData
plot(x, ...)

Value

An igraph network object is returned, invisibly.

Arguments

x

A GSNData object containing a pared distance matrix with edges.

...

Arguments passed on to gsnPlotNetwork

object

A GSNData object containing a pared distance matrix with edges. NOTE: when calling as plot.GSNData, use the argument x instead.

pathways_dat

(optional) data.frame containing associated pathways data. This defaults to whatever pathways data has already been imported into this GSNData object in object$pathways$data.

distance

(optional) The name of a distance metric used, defaults to whatever default_distance is.

id_col

(optional) This is the name of the column in the pathways data.frame that corresponds to the names of gene sets. The default value is specified by object$pathways$id_col. (See details.)

substitute_id_col

(optional) This is the name of the column that is to be substituted for the id_col column when labeling network vertices. (See details.)

stat_col

(optional) This is the name of the column in the pathways data.frame that contains a significance value for coloring network vertices. The default value is specified by object$pathways$stat_col.

stat_col_2

(optional) This is the name of an optional second column in the pathways data.frame that contains a significance value for coloring network vertices in a 2-color network. The default value is specified by object$pathways$stat_col_2. When specified, a 2-color network is generated. To force a 2-color network to plot as a standard 1-color network using stat_col alone, use stat_col_2 = NA.

sig_order

(optional) This indicates the behavior of stat_col, whether low values ('loToHi') or high values ('hiToLo') are most significant. The default value is specified in object$pathways$sig_order.

sig_order_2

(optional) This indicates the behavior of stat_col_2, whether low values ('loToHi') or high values ('hiToLo') are most significant. The default value is specified in object$pathways$sig_order_2.

n_col

(optional) This is the name of the column in the pathways data.frame that contains a value for gene set size, or any other value intended to be the bases of leaf scaling. When specified, leaf sizes will be scaled by this value, either as a function argument, or in the object$pathways$n_col field. An NA value can be used to override the the value in object$pathways$n_col and suppress leaf scaling when n_col has been set in the object. (default is the value in object$pathways$n_col).

optimal_extreme

(optional) This indicates the behavior of the statistic used to generate the distance metric, specifically whether low values ('min') or high values 'max' are to be regarded as close. This is used for scaling the width and the color of the edges connecting vertices. See scale.edges.by.distance, below: (default: object$distances[distance]$pared_optimal_extreme or if that's NULL, object$distances[distance]$optimal_extreme)

transform_function

(optional) This is a function to transform the values in stat_col so that they are suitable for amenable to color-scaling. For p-values, a log transformation is often useful, but can produce negative infinities if the transformation is applied to zero. By default the function is the nzLog10 (non-zero log10) function, provided by this package, which adds a small pseudocount to p-values when log10 transforming values equal to zero. If values in stat_col are less than zero, then log10 transformation is inappropriate and will introduce NAs, and therefore some other method should be used. (default: nzLog10)

pathways_title_col

(optional) Indicates a column to be used as the 'Title' column for network vertices. If unset, the function attempts to search for a title column from the following values: c("Title", "Name", "NAME", "STANDARD_NAME" ) (See details.)

edge_colors

(optional) A vector of colors included to generate a scale represent the numerical value of the edge distances. By default, the colors are arranged as a rainbow with black and purple representing the greatest distances, and orange and red the nearest distances. This feature (and argument) will likely be deprecated in future versions. (default: edge_colors = c("black", "purple", "blue", "green","yellow4", "orange","red"))

vertex_colors

(optional) This is the standard set of colors used for a standard single color network. By default, c("white","yellow","red") is used, coloring low values white, high values red, and intermediate values yellow if sig_order is "loToHi" and vice versa if sig_order is "hiToLo".

vertex_colors.1

(optional) This is the range of colors used for a 2-color network corresponding to values of stat_col. Up to 2 colors can be used, and should correspond to a color contrasting with vertex_colors.2. The default is c("white","red"), coloring high values red and low values white if sig_order is "loToHi" and vice versa if sig_order is "hiToLo".

vertex_colors.2

(optional) This is the range of colors used for a 2-color network corresponding to values of stat_col_2. Up to 2 colors can be used, and should correspond to a color contrasting with vertex_colors.2. The default is c("white","blue"), coloring high values blue and low values white if sig_order_2 is "loToHi" and vice versa if sig_order is "hiToLo".

combine_method

(optional) For dual channel plots this is a string used to indicate how colors are combined to generate a two dimensional color scale. Options are "scaled_geomean" (same as "default"), "standard" (same as "euclidean" ), "negative_euclidean", "mean", and "additive". See details.

na.color

(optional) This color is assigned to vertices for which there is an NA value. (default: "#CCCCCC")

filename

(optional) An output file name for the plot. If 'out_format' is not set (see below), the output file type will be determined by the file suffix, which can be '.svg', '.pdf', or '.png'. If the out_format cannot be determined from the file name, than it may be manually set with out_format. If the output file type cannot be determined from the filename or out_format arguments, an error will be thrown.

out_format

(optional) Output filetype when filename is specified, either 'svg', 'png', 'pdf', or 'plot' (default if filename is not specified). For more information, see Details.

width

(optional) Sets the width of the output canvas in inches. Defaults to the width of the present graphical device.

height

(optional) Sets the height of the output canvas in inches. Defaults to the height of the present graphical device.

vertex.shape

(optional) Shape of the vertex, passed to igraph::plot.igraph. By default, the value is 'circle'.

vertex.size

(optional) Size of vertices, passed to igraph::plot.igraph. By default, the value is NULL, and the function attempts to pick a reasonable value based on the canvas size and the number of gene sets.

vertex.size.range

(optional) The range of vertex sizes used in plots, from low to high. This is used when n_col is specified and vertex sizes are intended to be scaled. If this is not specified, then the function attempts to select appropriate values based on size of the figure being generated.

vertex.label.cex

(optional) Size of vertex labels, passed to igraph::plot.igraph. As with vertex.size, by default, the value is NULL, and the function attempts to pick a reasonable value based on the canvas size and the number of gene sets.

vertex.label.col

(optional) Color of vertex labels, passed to igraph::plot.igraph. If not specified, the function attempts to pick a contrasting color for vertex label text using the contrasting_color.fun argument. (default: NULL)

vertex.frame.color

(optional) Color of the vertex border. (default par('fg'))

contrasting_color.fun

(optional) A function to pick a color for vertex labels that contrasts with the vertex fill color. If unspecified, the function attempts to pick a suitable function for generating suitable set of contrasting colors, based on the contrasting_color() function. (default: For single channel plots using color scales defined with vertex_colors, or dual channel color scales defined with vertex_colors.1, or vertex_colors.2 using yellow or orange, contrasting_color(type="binary") is used, and otherwise contrasting_color(type="blackyellow") is used.)

scale_labels_by_vertex

(optional) Logical that tells the function to scale the text in vertex labels by the size of the vertex. (default: TRUE)

max_edge_width

(optional) Size of vertex labels, passed to igraph::plot.igraph. By default, the value is NULL, and the function attempts to pick a reasonable value based on the canvas size and the number of gene sets.

scale.edges.by.distance

(optional) A logical telling the function to scale edges between vertices on the basis of distance. NOTE: If optimal_extreme == "max", then smaller numbers are treated as more distant, and conversely if optimal_extreme == "min", larger numbers are treated as more distant. (default: FALSE)

color.edges.by.distance

(optional) A logical telling the function to color edges between vertices on the basis of distance. This functionality will likely be deprecated. (default: FALSE)

edge_arrow_size

(optional) Size of vertex labels, passed to igraph::plot.igraph. By default, the value is NULL, and the function attempts to pick a reasonable value based on the canvas size and the number of gene sets.

seed

(optional) This is a seed that the function uses to generate a plot layout. By default it is 29189892, and this results in a repeatable behavior for plots. However, to randomize the plot layout behavior, this value may be set to NULL, or if some other repeatable layout is desired, another seed may be used.

layout

(optional) Either a function that generates a layout or a numerical matrix containing a vertex layout with two columns corresponding to x and y coordinates. This argument is passed to the igraph plot method that is subsequently called by gsnPlotNetwork() (see .plot, below). The default layout is the anonymous function function(x){igraph::layout_with_fr(x, grid = "nogrid" )}, which calls igraph::layout_with_fr() (implementing Fruchterman-Reingold layout) with the grid="nogrid" option, enabling proper layout of networks with >= 1000 gene set vertices. Other useful layouts for igraph networks include igraph::layout_with_fr (default Fruchterman-Reingold), igraph::layout_with_dh (implementing Davidson-Harel layout), igraph::layout_as_tree, igraph::layout_nicely, and others. For more details about layouts, see igraph.plotting.

.plot

(optional) A plot function used to render the internally generated igraph object. By default igraph::plot.igraph is used, but for interactive plotting, igraph::tkplot may be used. For more details about plotting, see igraph.plotting.

show.legend

(optional) A logical value telling the function whether or not to show legends. Legends for vertex size and node color are currently supported. (default: TRUE)

legend.lab.cex

(optional) The font size of legend label text as cex units. If not specified, the function will attempt to pick an appropriate value based on the figure layout.

legend.axis.cex

(optional) The font size of legend axis text as cex units. If not specified, the function will attempt to pick an appropriate value based on the figure layout.

legend.fg

(optional) The foreground color of the legend that controls the color of text, axes, axis labels, ticks, and legend border. (default: par('fg'))

legend.bg

(optional) The background color of the legend. This argument doesn't currently work, and may be removed in the future. (default: "#CCCCCC" )

legend.vertex.fg

(optional) The border color of vertices for vertex size legends. This argument allows the legend vertex frame color to be set separately from vertex.frame.color. (default: vertex.frame.color)

legend.vertex.bg

(optional) The fill color of vertices for vertex size legends. (default: "#DDDDDD")

font_face

(optional) The font face used for the figure. (default: par("family"))

main

(optional) The plot title. (default: NULL)

cex.main

(optional) The font size in cex units of the main title. (default: 1.5 * par( 'cex' ))

mar.main

(optional) The number of lines set aside for a main title when main is used. (default: 3.2)

lines.main

(optional) The distance of the main title in lines from the top of the plot. (default: 0.9)

.mar.plot

(optional) The margins of the plot itself. If unspecified, the function will attempt to reserve enough room to the right of the plot for the legend or legends.

draw.legend.box.bool

(option) Logical indicating whether bounding boxes should be drawn for the legends.

legend.free.cex.bool

(optional) Logical allowing independent optimized sizing of legend label font sizes if TRUE. (default: FALSE)

legend_x_size.in

(optional) The width of the legend in inches. If not set, the function attempts to choose an appropriate value. (default: min(2,max(width*2/5,width-height)))

colors.n

(optional) The number of colors in for each channel in 1 or 2 channel plots. For single channel plots the number of colors is simply equal to this number. For dual channel plots the total number of colors in the legend is equal to the square of this number. (default: 100)

new

(optional) Logical telling the function (if true) that a new plot should be added to an existing device (if TRUE) or that the current device should be cleared and written over (if FALSE). (default: FALSE)

legend_spacing.x.in

(optional) Space between plot and legend in inches. This can be used to adjust the horizontal position and move the legend closer to or farther away from the plot region. Since the network plot may not fill the entire plotting region, it may be useful to use negative values to move the legends closer to the plot. (default: 2 character widths)

legend_spacing.y.in

(optional) Space between legends in inches. (default: 1 character height)

resolution

Image resolution in pixels per inch, only for bitmap image output formats (currently png only). (default: 72)

DO_BROWSER

(option) Logical indicating whether browser() should be run for this function. (For debugging purposes, will probably remove.)

Details

This function is primarily for taking GSNData object containing a distance matrix, an associated edges edge-list and pathways data, and generating and rendering a corresponding igraph object. The function attempts to plot the corresponding network with vertices labeled with a gene set ID and corresponding Title, and colored according to the significance values represented in stat_col using sig_order as an indicator of whether high or low values are more significant. Edges are scaled by the value of the value of the distance statistic in the pared distance matrix.

When the parameters vertex.shape, vertex.size, vertex.label.cex, max_edge_width, and edge_arrow_size are not specified, the function attempts to pick reasonable values. These parameters are assembled into a list and attached to the returned igraph object as an attribute named GSNA_plot_params. To optimize plots, the user can examine these parameters by calling the following on the output of the function:

attr( x = nw.igraph, which = "GSNA_plot_params" )

See Also

gsnPlotNetwork gsnToIgraph plot.igraph

Examples

Run this code

# \donttest{
# This example can take >10 seconds to run on some platforms,
# so we won't test it here.

library(GSNA)

# In this example, we generate a gene set network from CERNO example
# data. We begin by subsetting the CERNO data for significant results:
sig_pathways.cerno <- subset( Bai_CiHep_DN.cerno, adj.P.Val <= 0.05 )

# Now create a gene set collection containing just the gene sets
# with significant CERNO results, by subsetting Bai_gsc.tmod using
# the gene set IDs as keys:
sig_pathways.tmod <- Bai_gsc.tmod[sig_pathways.cerno$ID]

# And obtain a background gene set from differential expression data:
background_genes <- toupper( rownames( Bai_CiHep_v_Fib2.de ) )

# Build a gene set network:
sig_pathways.GSN <-
   buildGeneSetNetworkJaccard(geneSetCollection = sig_pathways.tmod,
                              ref.background = background_genes )

# Now import the CERNO data:
sig_pathways.GSN <- gsnImportCERNO( sig_pathways.GSN,
                                    pathways_data = sig_pathways.cerno )

# Now we can pare the network and assign subnets:
sig_pathways.GSN <- gsnPareNetGenericHierarchic( object = sig_pathways.GSN )
sig_pathways.GSN <- gsnAssignSubnets( sig_pathways.GSN )

# Now, produce a network plot:
gsnPlotNetwork( object  = sig_pathways.GSN )
# }

Run the code above in your browser using DataLab