*! version 1.0 20 Jun 2019

Title

plotmatrix -- Plot values of a matrix as different coloured blocks

Syntax

plotmatrix
[,
options]

Main
mat(name) specifies the name of the matrix to plot. Note that for matrices e(b) and e(V) the user must create a new matrix using the matrix command.

,

matse(name) specifies the name of the matrix to scale each square by. This could be the standard error of your main matrix.

split(numlist) specifies the cutpoints used in the legend. Note that if the matrix contains values outside the range of the number list then the values will not be plotted. The default will be a number list containing the min, max and 10 other percentiles.

color(string) specifies the colour of the blocks used. The default colour is bluish gray. Note that RGB and CMYK colors are not accepted and colors should be specified by the word list in colorstyle e.g. brown.

uppercolor(string) specifies the colour used in the upper triangular part of the matrix.

lowercolor(string) specifies the colour used in the lower triangular part of the matrix.

diagcolor(string) specifies the colour used in the diagonal part of the matrix.

allcolors(string) specifies the colours of the blocks used. Note you need to specify all the colours rather than a single colour used by the color() option.

nodiag specifies that the diagonal of the matrix is not represented in the graph.

save specifies that the stata data file created to plot the heatmap is saved.

addbox(numlist) specifies that areas of the graph will be enclosed within a box. The arguments of this option are groups of 4 numbers representing the (y,x) points of two extreme vertices of the box.

upper specifies that only the upper diagonal matrix be plotted.

lower specifies that only the lower diagonal matrix be plotted.

distance(varname) specifies the physical distances between rows/columns in the matrix. This is mostly useful for plotting a pairwise LD matrix to include the genomic distances between markers.

dunit(string) specifies the units of the distances specified in the distance variable. The default is Megabases but can be any string.

maxticks(#) specifies the maximum number of ticks on both the y and x axes. The default is 8.

freq specifies that the matrix values are displayed within each coloured box.

formatcells(string) specifies the format of the displayed matrix values within each coloured box.

blc(string) specifies the color for the outline of each box.

blw(string) specifies the thickness of the line surrounding each box, the default is vvvthin.

* other twoway options.

Description

This command will display the values of a matrix using twoway area. Each value of the matrix will be represented by a coloured rectangular block. A
legend is automatically created using percentiles but the user can also specify how to split the data.

For genetic data there is an additional function to show the genomic distances between markers. The genomic position is entered using the distance()
option.

Options

Main

mat(name) specifies the name of the matrix to plot. Note that for matrices e(b) and e(V) the user must create a new matrix using the matrix command.

,

matse(name) specifies the name of the matrix to scale each square by. This could be the standard error of your main matrix.

split(numlist) 1 specifies the cutpoints used in the legend. Note that if the matrix contains values outside the range of the number list then the values will not be plotted. The default will be a number list containing the min, max and 10 other percentiles.

color(string) specifies the colour of the blocks used. The default colour is bluish gray. Note that RGB and CMYK colors are not accepted and colors should be specified by the word list in colorstyle e.g. brown.

uppercolor(string) specifies the colour used in the upper triangular part of the matrix.

lowercolor(string) specifies the colour used in the lower triangular part of the matrix.

diagcolor(string) specifies the colour used in the diagonal part of the matrix.

allcolors(string) specifies the colours of the blocks used. Note you need to specify all the colours rather than a single colour used by the color() option.

nodiag specifies that the diagonal of the matrix is not represented in the graph.

save specifies that the stata data file created to plot the heatmap is saved.

addbox(numlist) specifies that areas of the graph will be enclosed within a box. The arguments of this option are groups of 4 numbers representing the (y,x) points of two extreme vertices of the box.

upper specifies that only the upper diagonal matrix be plotted.

lower specifies that only the lower diagonal matrix be plotted.

distance(varname) specifies the physical distances between rows/columns in the matrix. This is mostly useful for plotting a pairwise LD matrix to include the genomic distances between markers.

dunit(string) specifies the units of the distances specified in the distance variable. The default is Megabases but can be any string.

maxticks(#) specifies the maximum number of ticks on both the y and x axes. The default is 8.

freq specifies that the matrix values are displayed within each coloured box.

formatcells(string) specifies the format of the displayed matrix values within each coloured box.

blc(string) specifies the color for the outline of each box.

blw(string) specifies the thickness of the line surrounding each box, the default is vvvthin.

* other twoway options.

Examples

Plotting the values of a variance covariance matrix

sysuse auto <--- click this first to load data

reg price mpg trunk weight length turn, nocons

mat regmat = e(V)

plotmatrix, m(regmat) c(green) ylabel(,angle(0))

plotmatrix, m(regmat) allcolors(green*1 green*0.8 green*0.6 green*0.4 red*0.4 red*0.6 red*0.8 red*1.0 ) ylabel(,angle(0))

To make the plot above more square use the aspect() option but you might want to make the text smaller in the legend so that the y-axis is closer to
the interior of the plot.

plotmatrix, m(regmat) allcolors(green*1 green*0.8 green*0.6 green*0.4 red*0.4 red*0.6 red*0.8 red*1.0 ) ylabel(,angle(0)) aspect(1) legend(size(*.4) symx(*.4))

Plotting the values of a correlation matrix of a given varlist

matrix accum R = price mpg trunk weight length turn , nocons dev

matrix R = corr(R)

plotmatrix, m(R) s(-1(0.25)1) c(red)

By specifying the freq option the correlations are additional printed within each
coloured box. Negating the need for a legend.
plotmatrix, m(R) s(-1(0.25)1) c(red) freq legend(off) plotmatrix, m(R) s(-1(0.25)1) c(red) freq aspect(1) legend(size(*.4) symx(*.4))

With additional formatting on the cells
plotmatrix, m(R) s(-1(0.25)1) c(red) freq formatcells(%5.2f) aspect(1) legend(size(*.4) symx(*.4))

Genetic Examples

Plotting the values of a point-wise LD map (see command pwld), with boxes around two areas defined by variables 1-5 and variables 11-18.

.pwld l1_1-l76_2, mat(grid)

.plotmatrix, mat(grid) split( 0(0.1)1 ) c(gray) nodiag addbox(1 1 5 5 11 11 18 18)

Using the same data as above there were also map positions within the variable posn. Thus the genomic map could be displayed as a diagonal axis with the
following command

.plotmatrix , mat(grid) split( 0(0.1)1 ) c(gray) nodiag save l distance(posn) dunit(Mb)

Updating this command

To obtain the latest version click the following to uninstall the old version

ssc uninstall plotmatrix

And click here to install the new version

ssc install plotmatrix

Author

Prof Adrian Mander, Cardiff University.

Email mandera@cardiff.ac.uk