create.manhattanplot {BoutrosLab.plotting.general}R Documentation

Make a Manhattan plot

Description

Takes a data.frame and creates a Manhattan plot

Usage

create.manhattanplot(
	formula,
	data,
	filename = NULL,
	main = NULL,
	main.just = 'center',
	main.x = 0.5,
	main.y = 0.5,
	main.cex = 3,
	xlab.label = tail(sub('~', '', formula[-2]), 1),
	ylab.label = tail(sub('~', '', formula[-3]), 1),
	xlab.cex = 2,
	ylab.cex = 2,
	xlab.col = 'black',
	ylab.col = 'black',
	xlab.top.label = NULL,
	xlab.top.cex = 2,
	xlab.top.col = 'black',
	xlab.top.just = 'center',
	xlab.top.x = 0.5,
	xlab.top.y = 0,
	xlimits = NULL,
	ylimits = NULL,
	xat = TRUE,
	yat = TRUE,
	xaxis.lab = NA,
	yaxis.lab = NA,
	xaxis.log = FALSE,
	yaxis.log = FALSE,
	xaxis.cex = 1.5,
	yaxis.cex = 1.5,
	xaxis.rot = 0,
	yaxis.rot = 0,
	xaxis.fontface = 'plain',
	yaxis.fontface = 'plain',
	xaxis.col = 'black',
	yaxis.col = 'black',
	xaxis.tck = 0,
	yaxis.tck = c(1,1),
	horizontal = FALSE,
	type = 'p',
	cex = 2,
	pch = '.',
	col = 'black',
	lwd = 1,
	lty = 1,
	alpha = 1,
	strip.col = 'white',
	strip.cex = 1,
	axes.lwd = 1,
	axes.lty = 'dashed',
	key = list(text = list(lab = c(''))),
	legend = NULL,
	layout = NULL,
	as.table = FALSE,
	x.spacing = 0,
	y.spacing = 0,
	x.relation = 'same',
	y.relation = 'same',
	top.padding = 0,
	bottom.padding = 0,
	right.padding = 0,
	left.padding = 0,
	key.top = 0,
	key.left.padding = 0,
	ylab.axis.padding = 1,
	axis.key.padding = 1,
	abline.h = NULL,
	abline.col = 'black',
	abline.lwd = 1,
	abline.lty = 1,
	add.rectangle = FALSE,
	xleft.rectangle = NULL,
	ybottom.rectangle = NULL,
	xright.rectangle = NULL,
	ytop.rectangle = NULL,
	col.rectangle = 'transparent',
	alpha.rectangle = 1,
	add.points = FALSE,
	points.x = NULL,
	points.y = NULL,
	points.pch = 19,
	points.col = 'black',
	points.cex = 1,
	add.text = FALSE,
	text.labels = NULL,
	text.x = NULL,
	text.y = NULL,
	text.col = 'black',
	text.cex = 1,
	text.fontface = 'bold',
	height = 6,
	width = 10,
	size.units = 'in',
	resolution = 1600,
	enable.warnings = FALSE,
	style = 'BoutrosLab',
	description = 'Created with BoutrosLab.plotting.general',
	preload.default = 'custom',
        use.legacy.settings = FALSE,
        inside.legend.auto = FALSE,
	...
	);
    

Arguments

formula

The formula used to extract the x & y components from the data-frame

data

The data-frame to plot

filename

Filename for tiff output, or if NULL returns the trellis object itself

main

The main title for the plot (space is reclaimed if NULL)

main.just

The justification of the main title for the plot, default is centered

main.x

The x location of the main title, deault is 0.5

main.y

The y location of the main title, default is 0.5

main.cex

Size of text for main plot title

xlab.label

x-axis label

ylab.label

y-axis label

xlab.cex

Size of x-axis label, defaults to 2

ylab.cex

Size of y-axis label, defaults to 2

xlab.col

Colour of the x-axis label, defaults to “black”

ylab.col

Colour of the y-axis label, defaults to “black”

xlab.top.label

The label for the top x-axis

xlab.top.cex

Size of top x-axis label

xlab.top.col

Colour of the top x-axis label

xlab.top.just

Justification of the top x-axis label, defaults to centered

xlab.top.x

The x location of the top x-axis label

xlab.top.y

The y location of the top y-axis label

xlimits

Two-element vector giving the x-axis limits, defaults to automatic

ylimits

Two-element vector giving the y-axis limits, defaults to automatic

xat

Vector listing where the x-axis labels should be drawn, defaults to automatic

yat

Vector listing where the y-axis labels should be drawn, defaults to automatic

xaxis.lab

Vector listing x-axis tick labels, defaults to automatic

yaxis.lab

Vector listing y-axis tick labels, defaults to automatic

xaxis.log

Logical indicating whether x-variable should be in logarithmic scale (and what base if numeric)

yaxis.log

Logical indicating whether y-variable should be in logarithmic scale (and what base if numeric)

xaxis.cex

Size of x-axis scales, defaults to 1

yaxis.cex

Size of y-axis scales, defaults to 1

xaxis.rot

Counterclockwise rotation of text in x-axis scales in degrees, defaults to 0

yaxis.rot

Counterclockwise rotation of text in y-axis scales in degrees, defaults to 0

xaxis.fontface

Fontface for the x-axis scales

yaxis.fontface

Fontface for the y-axis scales

xaxis.col

Colour of the x-axis tick labels, defaults to “black”

yaxis.col

Colour of the y-axis tick labels, defaults to “black”

xaxis.tck

Specifies the length of the tick mark, defaults to 1 for both top and bottom axes

yaxis.tck

Specifies the length of the tick mark, defaults to 1 for both top and bottom axes

horizontal

xyplot-specific function that allows you to change if type='h' draws lines to the vertical or horizontal axis

type

Plot type

cex

Character expansion for plotting symbol

pch

Plotting character

col

Point/line colour

lwd

Specifies line width, defaults to 1

lty

Specifies line style, defaults to 1 (solid)

alpha

Specifies line transparency, defaults to 1 (opaque)

strip.col

Strip background colour, defaults to “white”

strip.cex

Strip title character expansion

axes.lwd

Thickness of width of axis lines

axes.lty

Specifies axis line style, defaults to “dashed”

key

A list giving the key (legend). The default suppresses drawing

legend

Add a legend to the plot. Helpful for adding multiple keys and adding keys to the margins of the plot. See xyplot.

layout

A vector specifying the number of columns, rows (e.g., c(2,1). Default is NULL; see lattice::xyplot for more details

as.table

Specifies panel drawing order, default is FALSE which draws panels from bottom left corner, moving right then up. Set to TRUE to draw from top left corner, moving right then down

F

x.spacing

A number specifying the distance between panels along the x-axis, defaults to 0

y.spacing

A number specifying the distance between panels along the y-axis, defaults to 0

x.relation

Allows x-axis scales to vary if set to “free”, defaults to “same”

y.relation

Allows y-axis scales to vary if set to “free”, defaults to “same”

top.padding

A number specifying the distance to the top margin, defaults to 0

bottom.padding

A number specifying the distance to the bottom margin, defaults to 0

right.padding

A number specifying the distance to the right margin, defaults to 0

left.padding

A number specifying the distance to the left margin, defaults to 0

key.top

A number specifying the distance at top of key, defaults to 0

key.left.padding

Amount of padding to go onto any legend on the left

ylab.axis.padding

A number specifying the distance of label to the y-axis, defaults to 1

axis.key.padding

A number specifying the distance from the y-axis to the key, defaults to 1

abline.h

Allow horizontal line to be drawn, default to NULL

abline.col

Horizontal line colour, defaults to black

abline.lwd

Specifies horizontal line width, defaults to 1

abline.lty

Specifies horizontal line style, defaults to 1 (solid)

add.rectangle

Allow a rectangle to be drawn, default is FALSE

xleft.rectangle

Specifies the left x coordinate of the rectangle to be drawn

ybottom.rectangle

Specifies the bottom y coordinate of the rectangle to be drawn

xright.rectangle

Specifies the right x coordinate of the rectangle to be drawn

ytop.rectangle

Specifies the top y coordinate of the rectangle to be drawn

col.rectangle

Specifies the colour to fill the rectangle's area

alpha.rectangle

Specifies the colour bias of the rectangle to be drawn

add.points

Allow additional points to be drawn, default is FALSE

points.x

The x co-ordinates where additional points should be drawn

points.y

The y co-ordinates where additional points should be drawn

points.pch

The plotting character for additional points

points.col

The colour of additional points

points.cex

The size of additional points

add.text

Allow additional text to be drawn, default is FALSE

text.labels

Labels for additional text

text.x

The x co-ordinates where additional text should be placed

text.y

The y co-ordinates where additional text should be placed

text.col

The colour of additional text

text.cex

The size of additional text

text.fontface

The fontface for additional text

height

Figure height, defaults to 6 inches

width

Figure width, defaults to 6 inches

size.units

Figure units, defaults to inches

resolution

Figure resolution in dpi, defaults to 1600

enable.warnings

Print warnings if set to TRUE, defaults to FALSE

style

defaults to “BoutrosLab”, also accepts “Nature”, which changes parameters according to Nature formatting requirements

description

Short description of image/plot; default NULL

preload.default

ability to set multiple sets of diffrent defaults depending on publication needs

use.legacy.settings

boolean to set wheter or not to use legacy mode settings (font)

inside.legend.auto

boolean specifying whether or not to use the automatic inside legend function

...

Additional arguments to be passed to xyplot

Value

If filename is NULL then returns the trellis object, otherwise creates a plot and returns a 0/1 success code.

Warning

If this function is called without capturing the return value, or specifying a filename, it may crash while trying to draw the histogram. In particular, if a script that uses such a call of create histogram is called by reading the script in from the command line, it will fail badly, with an error message about unavailable fonts:

    Error in grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x,  )
        Invalid font type
    Calls: print ... drawDetails.text -> grid.Call.graphics -> .Call.graphics
    

Author(s)

Christine P'ng, Cindy Q. Yao

See Also

xyplot, lattice or the Lattice book for an overview of the package.

Examples

set.seed(12345);
simple.data <- data.frame(
    x = runif(20000, 0, 1),
    y = 1:20000
    );

create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_Simple', fileext = '.tiff'),
    formula = -log10(x) ~ y,
    data = simple.data,
    main = 'Simple',
    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 50
    );

# set up chromosome covariate colours to use for chr covariate, below
chr.colours <- force.colour.scheme(microarray$Chr, scheme = 'chromosome');

# make chr covariate and chr labels 
chr.n.genes       <- vector();
chr.tck           <- vector();
chr.pos.genes     <- vector();
chr.break         <- vector();
chr.break[1]      <- 0;
# get a list of chromosomes to loop
chr <- unique(microarray$Chr);

# loop over each chromosome
for ( i in 1:length(chr) ) {

    # get the number of genes that belong to one chromosome
    n <- sum(microarray$Chr == chr[i]);

    # calculate where the labels go
    chr.n.genes[i]   <- n;
    chr.break[i+1] <- n + chr.break[i];
    chr.pos.genes[i] <- floor(chr.n.genes[i]/2);
    chr.tck[i]       <- chr.pos.genes[i] + which(microarray$Chr == chr[i])[1];
    }

# add an indicator function for the data-frame
microarray$ind <- 1:nrow(microarray);

# Minimal input
create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_Minimal_Input', fileext = '.tiff'),
    formula = -log10(pval) ~ ind,
    data = microarray,
    main = 'Minimal input',
    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 100
    );

# Custom Axes
create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_Custom_Axes', fileext = '.tiff'),
    formula = -log10(pval) ~ ind,
    data = microarray,
    main = 'Custom axes',
    xlab.label = expression('Chromosomes'),
    ylab.label = expression('P'['adjusted']),
    xat = chr.tck,
    xaxis.lab = c(1:22, 'X', 'Y'),
    xaxis.tck = 0,
    xaxis.cex = 1,
    yaxis.cex = 1,
    yat = seq(0,5,1),
    yaxis.lab = c(
        1,
        expression(10^-1),
        expression(10^-2),
        expression(10^-3),
        expression(10^-4)
        ),
    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 100
    );

# Colour scheme
create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_Colour_Scheme', fileext = '.tiff'),
    formula = -log10(pval) ~ ind,
    data = microarray,
    main = 'Colour scheme',
    xlab.label = expression('Chromosomes'),
    ylab.label = expression('P'['adjusted']),
    xat = chr.tck,
    xaxis.lab = c(1:22, 'X', 'Y'),
    xaxis.tck = 0,
    xaxis.cex = 1,
    yaxis.cex = 1,
    yat = seq(0,5,1),
    yaxis.lab = c(
        1,
        expression(10^-1),
        expression(10^-2),
        expression(10^-3),
        expression(10^-4)
        ),
    col = chr.colours,
    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 200
    );

# Plotting Character
create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_Plotting_Character', fileext = '.tiff'),
    formula = -log10(pval) ~ ind,
    data = microarray,
    main = 'Plotting character',
    xlab.label = expression('Chromosomes'),
    ylab.label = expression('P'['adjusted']),
    xat = chr.tck,
    xaxis.lab = c(1:22, 'X', 'Y'),
    xaxis.tck = 0,
    xaxis.cex = 1,
    yaxis.cex = 1,
    yat = seq(0,5,1),
    yaxis.lab = c(
        1,
        expression(10^-1),
        expression(10^-2),
        expression(10^-3),
        expression(10^-4)
        ),
    col = chr.colours,
    # Change plotting character and size of plotting character
    pch = 18,
    cex = 0.75,
    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 200
    );


# Line
create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_Added_Line', fileext = '.tiff'),
    formula = -log10(pval) ~ ind,
    data = microarray,
    main = 'Line',
    xlab.label = expression('Chromosomes'),
    ylab.label = expression('P'['adjusted']),
    xat = chr.tck,
    xaxis.lab = c(1:22, 'X', 'Y'),
    xaxis.tck = 0,
    xaxis.cex = 1,
    yaxis.cex = 1,
    yat = seq(0,5,1),
    yaxis.lab = c(
        1,
        expression(10^-1),
        expression(10^-2),
        expression(10^-3),
        expression(10^-4)
        ),
    col = chr.colours,
    pch = 18,
    cex = 0.75,
    # draw horizontal line
    abline.h = 2,
    abline.lty = 2,
    abline.lwd = 1,
    abline.col = 'black',
    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 200
    );

# Background shading
create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_BG', fileext = '.tiff'),
    formula = -log10(pval) ~ ind,
    data = microarray,
    main = 'Bg rectangles',
    xlab.label = expression('Chromosomes'),
    ylab.label = expression('P'['adjusted']),
    xat = chr.tck,
    xaxis.lab = c(1:22, 'X', 'Y'),
    xaxis.tck = 0,
    xaxis.cex = 1,
    yaxis.cex = 1,
    yat = seq(0,5,1),
    yaxis.lab = c(
        1,
        expression(10^-1),
        expression(10^-2),
        expression(10^-3),
        expression(10^-4)
        ),
    col = chr.colours,
    pch = 18,
    cex = 0.75,
    abline.h = 2,
    abline.lty = 2,
    abline.lwd = 1,
    abline.col = 'black',
    # Adding rectangles
    add.rectangle = TRUE,
    xleft.rectangle = chr.break[seq(1, length(chr.break) - 1, 2)],
    ybottom.rectangle = 0,
    xright.rectangle = chr.break[seq(2, length(chr.break) - 1, 2)],
    ytop.rectangle = 4.5,
    col.rectangle = 'grey',
    alpha.rectangle = 0.5,
    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 200
    );

# Nature style
create.manhattanplot(
    filename = tempfile(pattern = 'Manhattan_Nature_style', fileext = '.tiff'),
    formula = -log10(pval) ~ ind,
    data = microarray,
    main = 'Nature style',
    xat = chr.tck,
    xaxis.lab = c(1:22, 'X', 'Y'),
    xaxis.tck = 0,
    xaxis.cex = 1,
    yaxis.cex = 1,
    yat = seq(0,5,1),
    yaxis.lab = c(
        1,
        expression(10^-1),
        expression(10^-2),
        expression(10^-3),
        expression(10^-4)
        ),
    col = chr.colours,
    pch = 18,
    cex = 0.75,
    abline.h = 2,
    abline.lty = 2,
    abline.lwd = 1,
    abline.col = 'black',
    # Adding rectangles
    add.rectangle = TRUE,
    xleft.rectangle = chr.break[seq(1, length(chr.break) - 1, 2)],
    ybottom.rectangle = 0,
    xright.rectangle = chr.break[seq(2, length(chr.break) - 1, 2)],
    ytop.rectangle = 4.5,
    col.rectangle = 'grey',
    alpha.rectangle = 0.5,

    # set style to Nature 
    style = 'Nature',
    
    # demonstrating how to italicize character variables
    ylab.label = expression(paste('italicized ', italic('a'))),
  
    # demonstrating how to create en-dashes
    xlab.label = expression(paste('en dashs: 1','\u2013', '10'^'\u2013', ''^3)),

    description = 'Manhattan plot created using BoutrosLab.plotting.general',
    resolution = 1200
    );


[Package BoutrosLab.plotting.general version 6.0.3 Index]