ggSmoothExprPlot: ggSmoothExprPlot

Description Usage Arguments Value Author(s) See Also Examples

View source: R/aveytoolkit_ggSmoothExprPlot.R

Description

Wrapper around ggplot to transform data and plot profiles (e.g. expression or activity) over time

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ggSmoothExprPlot(
  x,
  mat,
  rows,
  method = "auto",
  formula = formula("y ~ x"),
  splitRowBy = NA,
  splitColBy = NA,
  colorBy = NULL,
  cols = NA,
  whichCols = NA,
  sep = ".",
  colorByLabel = "Response",
  ggtitle = TRUE,
  xlab = "Time (Days Post-Vaccination)",
  ylab = "Expression",
  colors = c("#1B9E77", "#D95F02", "#7570B3", "#E7298A", "#66A61E", "#E6AB02",
    "#A6761D", "#666666"),
  space = "fixed",
  scales = "fixed",
  fileName = NA,
  plot = TRUE
)

Arguments

x

the numeric x-axis variable for the plot (usually time)

mat

data.frame or matrix of values to plot with samples in columns

rows

row names or row indices of the items to be plotted

method

smoothing method (function). See stat_smooth

formula

a formula to use for smoothing in stat_smooth (e.g. the default "y ~ x" or "y ~ ns(x, 3)").

splitRowBy

a factor used to split the data by row in facet_grid

splitColBy

a factor used to split the data by col in facet_grid

colorBy

a factor used for coloring. No coloring will be done if NULL (default)

cols

substring to search for with "grep" in column names to be plotted

whichCols

the column indices or full column names

sep

a separator used in searching for cols in the column names

colorByLabel

the labels used for the color legend

ggtitle

logical. If TRUE, rows is coerced to character and passed to ggtitle

xlab

passed to xlab. Defaults to "Time (Post-Vaccination)"

ylab

passed to ylab. Defaults to "Expression"

colors

The colors to use. Defaults to the colors given by using RColorBrewer's "Dark2" pallette (but RColorBrewer is not called directly so is not required).

space

If "fixed", the default, all panels have the same size. If "free_y" their height will be proportional to the length of the y scale; if "free_x" their width will be proportional to the length of the x scale; or if "free" both height and width will vary. This setting has no effect unless the appropriate scales also vary.

scales

Are scales shared across all facets (the default, "fixed"), or do they vary across rows ("free_x"), columns ("free_y"), or both rows and columns ("free")

fileName

the name of a file to write a PDF to or NA to plot in standard graphics device.

plot

logical specifying whether or not to plot the plot(s). Default is TRUE.

Value

invisibly returns a list with 2 elements: ggplot: the ggplot object to be plotted (this can be added to dat: a named list of the data frame(s) passed to data in ggplot. The names come from converting the rows argument to a character vector.

Author(s)

Stefan Avey

See Also

ggplot2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
data(OrchardSprays)
## Example of functionality
library(Biobase)
data(sample.ExpressionSet, package="Biobase")
dat <- sample.ExpressionSet
## Normally x-axis is time but in this dataset there is no time
## so we will use the `score` as the x-axis
genderF <- dat$sex == "Female"
ggSmoothExprPlot(x=dat$score[genderF],
                 mat=exprs(dat),
                 rows="31345_at",
                 whichCols=which(genderF), # females only
                 colorBy=as.factor(dat$type)[genderF],
                 colorByLabel="Condition",
                 xlab="score")
## Not run: tmp <- ggSmoothExprPlot(x=times[subset], mat=expr, rows=gene,
                                 formula=formula("y ~ ns(x,3)"),
                                 whichCols=subset, colorBy=target[subset,respType],
                                 splitColBy=splitby,
                                 splitRowBy=as.factor(target[subset,"Study"]),
                                 ggtitle=TRUE, colorByLabel=respType, plot=TRUE)
## End(Not run)

stefanavey/aveytoolkit documentation built on March 5, 2020, 12:49 a.m.