| Title: | Publication-Ready Figures for Cancer Bioinformatics |
|---|---|
| Description: | A compact plotting toolkit for cancer bioinformatics figures. Provides publication-ready Kaplan-Meier curves with hazard ratios, ROC and time-dependent ROC curves, multiple-ROC comparisons, risk-score distributions, PCA and UMAP projections, boxplots and correlation plots, lasso coefficient paths, enrichment plots, and immune-infiltration radar charts. Palette helpers return colour-blind-friendly colours in journal styles. |
| Authors: | Feng Gao [aut, cre] |
| Maintainer: | Feng Gao <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.6.0 |
| Built: | 2026-09-16 06:16:12 UTC |
| Source: | https://github.com/gflab/gfplot |
Turns a two-column clinical matrix into a matrix of event indicators, with one column per follow-up limit. Observations beyond a limit are censored at that limit.
generate_time_event(clinical, limits, labels = NULL)generate_time_event(clinical, limits, labels = NULL)
clinical |
Two-column object: follow-up time and event indicator. |
limits |
Numeric vector of follow-up limits. |
labels |
Optional column names for the resulting matrix. |
A matrix with one column per limit.
clinical <- cbind(time = c(1, 5, 10), event = c(1, 0, 1)) generate_time_event(clinical, limits = c(3, 6), labels = c("year3", "year6"))clinical <- cbind(time = c(1, 5, 10), event = c(1, 0, 1)) generate_time_event(clinical, limits = c(3, 6), labels = c("year3", "year6"))
Returns a vector of journal-style colours. When palette is a vector of
length greater than one it is returned unchanged, so the argument can also
be used to pass colours through from a caller.
get_color(palette, n = 6)get_color(palette, n = 6)
palette |
Palette name: |
n |
Number of colours to return. |
A character vector of colours.
get_color("jama", 3) get_color("house", 4) get_color(c("#111111", "#222222"))get_color("jama", 3) get_color("house", 4) get_color(c("#111111", "#222222"))
Returns the colours gfplot uses, addressed by role rather than by hex
value. Override any role for a session with
options(gfplot.palette = list(primary = "#123456")), which is how the
suite is retuned without editing figures.
gfplot_colors(role = "all")gfplot_colors(role = "all")
role |
Colour roles to return. Use |
A named character vector of colours.
get_color() for journal palettes and gfplot_theme() for the
type and grid settings that go with these colours.
gfplot_colors("primary") gfplot_colors(c("model_curve", "comparator_curve")) gfplot_colors("series")gfplot_colors("primary") gfplot_colors(c("model_curve", "comparator_curve")) gfplot_colors("series")
Returns an index of the available figure families with the category they
belong to and how to call them. Families with type = "spec" are driven by
gfplot_spec() and gfplot_render(); families with type = "function" are
called directly.
gfplot_families(category = NULL)gfplot_families(category = NULL)
category |
Optional category to filter by. |
A tibble with one row per family: the family name, its title and category, whether it is driven by a specification, the function that draws it, and an example call.
gfplot_spec() to build a figure programmatically.
gfplot_families() gfplot_families("Effect Estimate")gfplot_families() gfplot_families("Effect Estimate")
Figures produced by gfplot use Arial. The raster devices supplied by
ragg and the quartz device on macOS resolve system fonts such as
Arial directly, so most output needs no preparation at all. The base
pdf() device keeps its own font table and needs the family registered
with it, which extrafont does.
gfplot_font_setup(font = "Arial", quiet = FALSE)gfplot_font_setup(font = "Arial", quiet = FALSE)
font |
Font family to check. |
quiet |
Suppress the report. |
This function reports which routes work in the current session and, when
vector PDF output would otherwise be unavailable, registers the font with
extrafont so that pdf() can use it.
A named logical vector, invisibly, with one entry per device route:
raster (ragg PNG/TIFF/JPEG), quartz (macOS PDF and screen),
and pdf (base pdf()). These are the routes gfplot_save() chooses
between.
gfplot_save() to write a figure using a device that can render
the font, and plot_KMCurve() for the font argument.
gfplot_font_setup()gfplot_font_setup()
Legends in gfplot figures sit under the panel and wrap onto as many rows
as the number of series needs, so a wide legend does not squeeze the panel.
gfplot_legend(labels, base_size = 11, hide_single = TRUE)gfplot_legend(labels, base_size = 11, hide_single = TRUE)
labels |
Series labels the legend will show. |
base_size |
Base font size, used to scale the legend keys. |
hide_single |
Hide the legend when only one series is present, where it
would only restate the axis. Set to |
A ggplot2 guide specification, or "none" for a single series
when hide_single = TRUE.
gfplot_legend(c("Low risk", "High risk"))gfplot_legend(c("Low risk", "High risk"))
Draw a figure from a specification
gfplot_render(spec)gfplot_render(spec)
spec |
A specification from |
A ggplot object, ready to print or pass to gfplot_save().
effects <- data.frame( term = c("Age", "Stage III"), hr = c(1.02, 1.84), lower = c(0.99, 1.51), upper = c(1.05, 2.24) ) p <- gfplot_render(gfplot_spec( "forest", data = effects, term = "term", estimate = "hr", lower = "lower", upper = "upper" ))effects <- data.frame( term = c("Age", "Stage III"), hr = c(1.02, 1.84), lower = c(0.99, 1.51), upper = c(1.05, 2.24) ) p <- gfplot_render(gfplot_spec( "forest", data = effects, term = "term", estimate = "hr", lower = "lower", upper = "upper" ))
Writing an R figure with Arial is device dependent: the base pdf() device
needs the family registered with it, while the ragg raster devices
and the macOS quartz device resolve system fonts directly. This function
chooses a route that can render font for the requested file extension, so
a figure is written with the intended typeface instead of silently falling
back to a default.
gfplot_save( plot, filename, width = NULL, height = NULL, dpi = 300, size = NULL, font = "Arial", provenance = FALSE, call = NULL, ... )gfplot_save( plot, filename, width = NULL, height = NULL, dpi = 300, size = NULL, font = "Arial", provenance = FALSE, call = NULL, ... )
plot |
A |
filename |
Output path. The extension selects the device: |
width, height
|
Size in inches. Default to 7 by 5, or to the |
dpi |
Resolution for raster output. |
size |
Journal size preset, used when |
font |
Font family passed to the device unchanged. |
provenance |
Write a |
call |
The call to record in the provenance file. Defaults to the function as it was invoked. |
... |
Passed on to the device function. |
filename, invisibly. The path of the provenance file is attached
as the "provenance" attribute when one is written.
gfplot_font_setup() to see which devices can render a font.
p <- plot_Boxplot(c(rnorm(20), rnorm(20, 1)), rep(c("A", "B"), each = 20)) path <- tempfile(fileext = ".png") gfplot_save(p, path, width = 4, height = 3) unlink(path)p <- plot_Boxplot(c(rnorm(20), rnorm(20, 1)), rep(c("A", "B"), each = 20)) path <- tempfile(fileext = ".png") gfplot_save(p, path, width = 4, height = 3) unlink(path)
Captures the data and the settings for one figure as a value, validates
them, and returns an object that gfplot_render() turns into a ggplot.
Use this when the figure is decided in one place and drawn in another, or
when a specification needs to be stored, compared, or passed across a
process boundary.
gfplot_spec(family, ...)gfplot_spec(family, ...)
family |
Figure family, for example |
... |
Family-specific arguments. For |
Call gfplot_families() for the available families and their required
arguments.
An object of class gfplot_spec.
gfplot_render(), plot_forest()
effects <- data.frame( term = c("Age", "Stage III"), hr = c(1.02, 1.84), lower = c(0.99, 1.51), upper = c(1.05, 2.24) ) spec <- gfplot_spec( "forest", data = effects, term = "term", estimate = "hr", lower = "lower", upper = "upper" ) speceffects <- data.frame( term = c("Age", "Stage III"), hr = c(1.02, 1.84), lower = c(0.99, 1.51), upper = c(1.05, 2.24) ) spec <- gfplot_spec( "forest", data = effects, term = "term", estimate = "hr", lower = "lower", upper = "upper" ) spec
The theme every gfplot figure is drawn with: bold axis titles, a thin
major grid, a panel border, and a horizontal legend under the panel. Sizes
derive from base_size, so one number rescales the figure.
gfplot_theme( base_size = 11, font = "Arial", grid = TRUE, border = TRUE, legend = c("bottom", "right", "top", "left", "none"), margin = c(9, 10, 8, 10) )gfplot_theme( base_size = 11, font = "Arial", grid = TRUE, border = TRUE, legend = c("bottom", "right", "top", "left", "none"), margin = c(9, 10, 8, 10) )
base_size |
Base font size in points. Other sizes are derived from it. |
font |
Font family. Defaults to Arial. |
grid |
Draw the major grid. |
border |
Draw the panel border. |
legend |
Legend position, one of |
margin |
Plot margin in points, in the order top, right, bottom, left. |
This theme is also the session baseline: attaching gfplot sets it as the
global ggplot2 theme so that figures drawn by other packages match. Set
options(gfplot.set_theme = FALSE) before library(gfplot) to keep an
existing theme instead.
A ggplot2 theme object.
gfplot_colors() for the colours that go with it.
library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + gfplot_theme()library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + gfplot_theme()
Computes the enrichment score with DOSE::gseaScores() and the p-value
with fgsea, then draws the running score with the leading-edge position.
ggGSEA(input, gs, title = "")ggGSEA(input, gs, title = "")
input |
Named numeric vector of ranked statistics. |
gs |
Gene set: a character vector of gene names. |
title |
Plot title. |
A ggplot object.
Draws the mean of value per group with standard error bars, and adds
pairwise significance labels when comparisons is supplied.
plot_barplot( value, group, comparisons = NULL, palette = "house", color = NULL, ylab = "Score", xlab = NULL, title = NULL, font = "Arial", label = "p.signif" )plot_barplot( value, group, comparisons = NULL, palette = "house", color = NULL, ylab = "Score", xlab = NULL, title = NULL, font = "Arial", label = "p.signif" )
value |
Numeric values to summarise. |
group |
Grouping vector, one value per observation. |
comparisons |
Optional list of length-two vectors naming the groups to
compare, for example |
palette |
Palette name passed to |
color |
Optional vector of fill colours; overrides |
ylab, xlab, title
|
Axis and plot labels. |
font |
Font family used in the plot. |
label |
Significance label style passed to
|
This function replaced the 0.1.0 plot_barplot(), which took no arguments
and could not be called.
A ggplot object.
set.seed(1) p <- plot_barplot( value = c(rnorm(20), rnorm(20, 1)), group = rep(c("A", "B"), each = 20) ) if (requireNamespace("ggpubr", quietly = TRUE)) { p <- plot_barplot( value = c(rnorm(20), rnorm(20, 1), rnorm(20, 2)), group = rep(c("A", "B", "C"), each = 20), comparisons = list(c("A", "B"), c("B", "C")) ) }set.seed(1) p <- plot_barplot( value = c(rnorm(20), rnorm(20, 1)), group = rep(c("A", "B"), each = 20) ) if (requireNamespace("ggpubr", quietly = TRUE)) { p <- plot_barplot( value = c(rnorm(20), rnorm(20, 1), rnorm(20, 2)), group = rep(c("A", "B", "C"), each = 20), comparisons = list(c("A", "B"), c("B", "C")) ) }
Boxplot with optional pairwise significance annotations
plot_Boxplot( value, label, palette = "house", title = NULL, ylab = "Expression", font = "Arial" )plot_Boxplot( value, label, palette = "house", title = NULL, ylab = "Expression", font = "Arial" )
value |
Numeric values. |
label |
Grouping vector. |
palette |
Palette name passed to |
title |
Plot title. |
ylab |
Y-axis label. |
font |
Font family used in the plot. |
A ggplot object.
set.seed(1) p <- plot_Boxplot(c(rnorm(20), rnorm(20, 1)), rep(c("A", "B"), each = 20))set.seed(1) p <- plot_Boxplot(c(rnorm(20), rnorm(20, 1)), rep(c("A", "B"), each = 20))
Predicted probability against the observed proportion of events. A model whose points sit on the diagonal predicts the level it claims; one above the diagonal under-predicts risk and one below over-predicts.
plot_calibration( probability, outcome, positive = NULL, bins = 10, smooth = FALSE, show_ci = TRUE, palette = "house", ci_level = 0.95, xlab = "Predicted probability", ylab = "Observed proportion", title = NULL, font = "Arial" )plot_calibration( probability, outcome, positive = NULL, bins = 10, smooth = FALSE, show_ci = TRUE, palette = "house", ci_level = 0.95, xlab = "Predicted probability", ylab = "Observed proportion", title = NULL, font = "Arial" )
probability |
Predicted probabilities, or a matrix or data frame with one column per model. |
outcome |
Binary outcome, one value per observation. |
positive |
Value of |
bins |
Number of groups to divide the predictions into. Quantile bins are used, so every point rests on a similar number of observations. |
smooth |
Draw a loess curve through the points instead of connecting them. |
show_ci |
Draw binomial confidence intervals for each point. |
palette |
Palette name passed to |
ci_level |
Confidence level of the intervals. |
xlab, ylab, title
|
Axis and plot labels. |
font |
Font family used in the plot. |
A ggplot object.
plot_ROC() for discrimination, plot_decision_curve() for
whether acting on the predictions helps.
set.seed(1) outcome <- rbinom(200, 1, 0.4) probability <- plogis(rnorm(200) + outcome * 0.5) p <- plot_calibration(probability, outcome)set.seed(1) outcome <- rbinom(200, 1, 0.4) probability <- plogis(rnorm(200) + outcome * 0.5) p <- plot_calibration(probability, outcome)
Predicted against actual class, with the count in each cell. Percentages are given per actual class, which is the direction that shows sensitivity and specificity; overall percentages would hide a class the model misses.
plot_confusion( predicted = NULL, actual = NULL, predicted_labels = NULL, actual_labels = NULL, positive = NULL, show = c("count", "percent", "both"), digits = 1, title = NULL, font = "Arial" )plot_confusion( predicted = NULL, actual = NULL, predicted_labels = NULL, actual_labels = NULL, positive = NULL, show = c("count", "percent", "both"), digits = 1, title = NULL, font = "Arial" )
predicted, predicted_labels
|
Predicted class labels. |
actual, actual_labels
|
Actual class labels. |
positive |
Value of the outcome that counts as the positive class,
used to order and label the axes. With |
show |
Which numbers to print: |
digits |
Significant digits for percentages. |
title |
Plot title. |
font |
Font family used in the plot. |
A ggplot object.
set.seed(1) actual <- rbinom(200, 1, 0.4) predicted <- ifelse(runif(200) < 0.8, actual, 1 - actual) p <- plot_confusion(predicted, actual, positive = 1)set.seed(1) actual <- rbinom(200, 1, 0.4) predicted <- ifelse(runif(200) < 0.8, actual, 1 - actual) p <- plot_confusion(predicted, actual, positive = 1)
Plot the correlation between two variables
plot_cor(x, y, groups = NULL, xlab = NULL, ylab = NULL, legend.pos = "top")plot_cor(x, y, groups = NULL, xlab = NULL, ylab = NULL, legend.pos = "top")
x, y
|
Numeric vectors. |
groups |
Optional grouping vector used to colour the points. |
xlab, ylab
|
Axis labels. |
legend.pos |
Legend position. |
A ggplot object.
p <- plot_cor(iris$Sepal.Length, iris$Sepal.Width)p <- plot_cor(iris$Sepal.Length, iris$Sepal.Width)
The probability of each event type over follow-up, in the presence of competing events. When a patient can experience one of several mutually exclusive events, a Kaplan-Meier estimate of any single one is biased upward, because patients who had a competing event are still counted as being at risk of the event of interest. The cumulative incidence function accounts for them.
plot_cumulative_incidence( time, status, group = NULL, event = NULL, conf_int = FALSE, palette = "house", xlab = "Follow up", ylab = "Cumulative incidence", title = NULL, legend_title = NULL, font = "Arial" )plot_cumulative_incidence( time, status, group = NULL, event = NULL, conf_int = FALSE, palette = "house", xlab = "Follow up", ylab = "Cumulative incidence", title = NULL, legend_title = NULL, font = "Arial" )
time |
Follow-up times. |
status |
Event type per patient. The first level is the event of
interest, |
group |
Optional grouping vector, giving one panel per group. |
event |
Optional event type to plot. By default every event type is drawn. |
conf_int |
Draw pointwise confidence bands. |
palette |
Palette name passed to |
xlab, ylab, title
|
Axis and plot labels. |
legend_title |
Legend title. |
font |
Font family used in the plot. |
A ggplot object.
plot_KMCurve() for a single event where no competing risk
applies.
set.seed(1) time <- rexp(200) status <- sample(c(0, 1, 2), 200, replace = TRUE, prob = c(0.4, 0.4, 0.2)) p <- plot_cumulative_incidence(time, status, group = rep(c("A", "B"), 100))set.seed(1) time <- rexp(200) status <- sample(c(0, 1, 2), 200, replace = TRUE, prob = c(0.4, 0.4, 0.2)) p <- plot_cumulative_incidence(time, status, group = rep(c("A", "B"), 100))
Net benefit across decision thresholds. Net benefit weights the true positives a model finds against the false positives it costs, at the threshold probability a clinician would use to act. It is the figure that answers whether using the model is better than treating everyone or no one.
plot_decision_curve( probability, outcome, positive = NULL, thresholds = seq(0.01, 0.5, by = 0.01), treat_all = TRUE, treat_none = TRUE, palette = "house", xlab = "Threshold probability", ylab = "Net benefit", title = NULL, font = "Arial" )plot_decision_curve( probability, outcome, positive = NULL, thresholds = seq(0.01, 0.5, by = 0.01), treat_all = TRUE, treat_none = TRUE, palette = "house", xlab = "Threshold probability", ylab = "Net benefit", title = NULL, font = "Arial" )
probability |
Predicted probabilities, or a matrix or data frame with one column per model. |
outcome |
Binary outcome, one value per observation. |
positive |
Value of |
thresholds |
Decision thresholds to evaluate. Defaults to 0.01 to 0.5, which covers the range used in most clinical decisions. |
treat_all |
Draw the reference curve for treating every patient. |
treat_none |
Draw the reference line for treating no patient. |
palette |
Palette name passed to |
xlab, ylab, title
|
Axis and plot labels. |
font |
Font family used in the plot. |
A ggplot object.
plot_calibration() for whether the predicted levels are honest.
set.seed(1) outcome <- rbinom(300, 1, 0.3) probability <- plogis(rnorm(300) + outcome) p <- plot_decision_curve(probability, outcome)set.seed(1) outcome <- rbinom(300, 1, 0.3) probability <- plogis(rnorm(300) + outcome) p <- plot_decision_curve(probability, outcome)
Plot samples in a two-dimensional embedding, coloured by group. The
embedding can be supplied already computed, or computed here from a feature
matrix with stats::prcomp(), Rtsne, or umap.
plot_embedding( data, groups, method = c("pca", "tsne", "umap", "none"), perplexity = 30, seed = NULL, ellipse = FALSE, label_centres = FALSE, palette = "house", title = NULL, xlab = NULL, ylab = NULL, font = "Arial" )plot_embedding( data, groups, method = c("pca", "tsne", "umap", "none"), perplexity = 30, seed = NULL, ellipse = FALSE, label_centres = FALSE, palette = "house", title = NULL, xlab = NULL, ylab = NULL, font = "Arial" )
data |
A feature matrix with samples in rows, or a two-column matrix of
coordinates when |
groups |
Group labels, one per sample. |
method |
Embedding to compute: |
perplexity |
Perplexity for t-SNE. Values much larger than the number of samples are rejected by the back end. |
seed |
Optional seed for the stochastic embeddings. |
ellipse |
Draw a confidence ellipse per group. |
label_centres |
Label each group at the centre of its points. |
palette |
Palette name passed to |
title, xlab, ylab
|
Axis and plot labels. |
font |
Font family used in the plot. |
plot_PCA() and plot_UMAP() are thin wrappers around this function, so a
figure keeps the same look whichever embedding it shows.
A ggplot object.
set.seed(1) data <- matrix(rnorm(200), nrow = 20) groups <- rep(c("A", "B"), each = 10) p <- plot_embedding(data, groups, method = "pca")set.seed(1) data <- matrix(rnorm(200), nrow = 20) groups <- rep(c("A", "B"), each = 10) p <- plot_embedding(data, groups, method = "pca")
Draws point estimates with confidence intervals on a horizontal axis, with
the numbers printed alongside. This is the standard display for hazard
ratios, odds ratios, and mean differences, and it reads a table straight
from clinstats::cox_table() or clinstats::logistic_table().
plot_forest( data, term, estimate, lower, upper, p = NULL, group = NULL, label = NULL, log_scale = FALSE, ref_line = NULL, estimate_label = "Estimate (95% CI)", p_label = "P", show_table = TRUE, digits = 2, xlab = NULL, title = NULL, font = "Arial" )plot_forest( data, term, estimate, lower, upper, p = NULL, group = NULL, label = NULL, log_scale = FALSE, ref_line = NULL, estimate_label = "Estimate (95% CI)", p_label = "P", show_table = TRUE, digits = 2, xlab = NULL, title = NULL, font = "Arial" )
data |
Data frame holding the estimates. |
term |
Column of row labels, one per estimate. |
estimate |
Column of point estimates. |
lower, upper
|
Columns of the confidence limits. |
p |
Optional column of p-values, shown as a right-hand column. |
group |
Optional column naming the section each estimate belongs to. Sections are drawn as facets with a shared axis. |
label |
Optional column overriding |
log_scale |
Plot the axis on a log scale, which is what ratios need so that a halving and a doubling are the same distance. |
ref_line |
Value of the reference line. Defaults to 1 when
|
estimate_label |
Column heading for the estimate table. |
p_label |
Column heading for the p-value column. |
show_table |
Print the estimate and p-value columns. |
digits |
Significant digits for the printed numbers. |
xlab, title
|
Axis and plot labels. |
font |
Font family used in the plot. |
A ggplot object, or a composed panel when show_table = TRUE,
as with the risk table of plot_KMCurve(). Both print and save the same
way.
gfplot_spec() to build the same figure as a value. The companion
package clinstats produces the estimates this draws.
effects <- data.frame( term = c("Age, per year", "Stage III vs II", "MSI-high"), hr = c(1.02, 1.84, 0.62), lower = c(0.99, 1.51, 0.44), upper = c(1.05, 2.24, 0.88), p = c(0.21, 4.1e-07, 0.008) ) p <- plot_forest( effects, term = "term", estimate = "hr", lower = "lower", upper = "upper", p = "p", log_scale = TRUE ) # Straight from a clinstats table if (requireNamespace("clinstats", quietly = TRUE)) { tbl <- clinstats::cox_table( clinstats::clin_crc, time = "rfs.delay", event = "rfs.event", factors = c("sex", "age", "tnm.stage"), multivariable = "none" ) p <- plot_forest( tbl, term = "term", estimate = "hr_univariable", lower = "univ_ci_lower", upper = "univ_ci_upper", p = "univ_p", log_scale = TRUE ) }effects <- data.frame( term = c("Age, per year", "Stage III vs II", "MSI-high"), hr = c(1.02, 1.84, 0.62), lower = c(0.99, 1.51, 0.44), upper = c(1.05, 2.24, 0.88), p = c(0.21, 4.1e-07, 0.008) ) p <- plot_forest( effects, term = "term", estimate = "hr", lower = "lower", upper = "upper", p = "p", log_scale = TRUE ) # Straight from a clinstats table if (requireNamespace("clinstats", quietly = TRUE)) { tbl <- clinstats::cox_table( clinstats::clin_crc, time = "rfs.delay", event = "rfs.event", factors = c("sex", "age", "tnm.stage"), multivariable = "none" ) p <- plot_forest( tbl, term = "term", estimate = "hr_univariable", lower = "univ_ci_lower", upper = "univ_ci_upper", p = "univ_p", log_scale = TRUE ) }
Plots the most significant terms with gene ratio on the x-axis, term on the y-axis, point size by gene count, and colour by significance.
plot_GO(gsea, n = 20, font = "Arial")plot_GO(gsea, n = 20, font = "Arial")
gsea |
Result table with the columns |
n |
Maximum number of terms to display. |
font |
Font family used in the plot. |
A ggplot object.
Draws the values of a matrix as tiles with a colourbar. This is the display for correlation matrices, signature scores by group, and any rectangular table of values where the pattern matters more than the numbers.
plot_heatmap( matrix, row_order = NULL, column_order = NULL, values = FALSE, digits = 2, midpoint = NULL, diverging = FALSE, low = NULL, mid = NULL, high = NULL, legend_label = "Value", title = NULL, font = "Arial" )plot_heatmap( matrix, row_order = NULL, column_order = NULL, values = FALSE, digits = 2, midpoint = NULL, diverging = FALSE, low = NULL, mid = NULL, high = NULL, legend_label = "Value", title = NULL, font = "Arial" )
matrix |
Numeric matrix, or a data frame whose columns are numeric. |
row_order, column_order
|
Optional ordering of rows and columns. Use
|
values |
Print the numeric value in each tile. |
digits |
Significant digits for the printed values. |
midpoint |
Value mapped to the middle of the colourbar. Defaults to the median, which centres a diverging scale on a typical value. |
diverging |
Use a diverging scale, for values that have a meaningful centre such as a correlation. |
low, mid, high
|
Colours for the low, middle, and high ends. |
legend_label |
Title of the colourbar. |
title |
Plot title. |
font |
Font family used in the plot. |
A ggplot object.
set.seed(1) m <- cor(matrix(rnorm(60), nrow = 20)) diag(m) <- NA p <- plot_heatmap(m, diverging = TRUE, midpoint = 0, legend_label = "Correlation")set.seed(1) m <- cor(matrix(rnorm(60), nrow = 20)) diag(m) <- NA p <- plot_heatmap(m, diverging = TRUE, midpoint = 0, legend_label = "Correlation")
Radar chart of immune-cell infiltration by group
plot_immune(res, group, title = "", legend.position = "left")plot_immune(res, group, title = "", legend.position = "left")
res |
Immune-cell estimates with cell types in the first column and samples in the remaining columns. |
group |
Named group labels, indexed by sample. |
title |
Plot title. |
legend.position |
Legend position. |
A ggplot object.
Draws survival curves for two or more groups, with an optional number-at- risk table, the log-rank p-value, and, for two groups, the hazard ratio from a univariable Cox model.
plot_KMCurve( clinical, labels, limit = NULL, annot = NULL, color = NULL, font = "Arial", xlab = "Follow up", ylab = "Survival Probability", title = NULL, legend.pos = "top", palette = "house", risk.table = TRUE, risk.table.ratio = 0.4, anno.pos = "bottom", anno.x.shift = 0.5 )plot_KMCurve( clinical, labels, limit = NULL, annot = NULL, color = NULL, font = "Arial", xlab = "Follow up", ylab = "Survival Probability", title = NULL, legend.pos = "top", palette = "house", risk.table = TRUE, risk.table.ratio = 0.4, anno.pos = "bottom", anno.x.shift = 0.5 )
clinical |
A survival object created by |
labels |
A vector of group labels, one per patient. |
limit |
Optional follow-up limit; later observations are censored at the limit. |
annot |
Optional extra annotation added to the plot. |
color |
Optional vector of colours. A named vector also sets the group order. |
font |
Font family used in the plot. |
xlab, ylab, title
|
Axis and plot labels. |
legend.pos |
Legend position. |
palette |
Palette name passed to |
risk.table |
Draw the number-at-risk table. |
risk.table.ratio |
Relative height of the risk table. |
anno.pos |
Either |
anno.x.shift |
Horizontal position of the annotations when
|
A ggplot object, or a cowplot grid when risk.table = TRUE.
if (requireNamespace("survminer", quietly = TRUE)) { fit_data <- survival::lung p <- plot_KMCurve( survival::Surv(fit_data$time, fit_data$status == 2), factor(fit_data$sex), risk.table = FALSE ) }if (requireNamespace("survminer", quietly = TRUE)) { fit_data <- survival::lung p <- plot_KMCurve( survival::Surv(fit_data$time, fit_data$status == 2), factor(fit_data$sex), risk.table = FALSE ) }
Draws the coefficient paths of a fitted glmnet model against the log
lambda sequence and labels the coefficients that remain non-zero at the
selected value of s.
plot_lasso(fit, s, font = "Arial")plot_lasso(fit, s, font = "Arial")
fit |
A fitted model from |
s |
Selected value of the penalty parameter. |
font |
Font family used in the plot. |
A ggplot object.
if (requireNamespace("glmnet", quietly = TRUE)) { set.seed(1) x <- matrix(rnorm(100 * 5), nrow = 100) y <- rnorm(100) + x[, 1] p <- plot_lasso(glmnet::glmnet(x, y), s = 0.05) }if (requireNamespace("glmnet", quietly = TRUE)) { set.seed(1) x <- matrix(rnorm(100 * 5), nrow = 100) y <- rnorm(100) + x[, 1] p <- plot_lasso(glmnet::glmnet(x, y), s = 0.05) }
Each element of scores is matched with the corresponding element of
labels, which allows the curves to come from different cohorts or
endpoints rather than from different markers of the same cohort.
plot_MulROC( scores, labels, palette = "house", color = NULL, legend.pos = "bottom", title = NULL, font = "Arial", percent.style = FALSE )plot_MulROC( scores, labels, palette = "house", color = NULL, legend.pos = "bottom", title = NULL, font = "Arial", percent.style = FALSE )
scores |
A named list of numeric marker vectors. |
labels |
A list of binary outcomes, one per element of |
palette |
Palette name passed to |
color |
Optional vector of colours; overrides |
legend.pos |
Legend position: a position such as |
title |
Plot title. |
font |
Font family used in the plot. |
percent.style |
Label the axes as percentages. |
A ggplot object.
set.seed(1) scores <- list(cohortA = rnorm(60), cohortB = rnorm(60)) labels <- list(rbinom(60, 1, 0.5), rbinom(60, 1, 0.5)) p <- plot_MulROC(scores, labels)set.seed(1) scores <- list(cohortA = rnorm(60), cohortB = rnorm(60)) labels <- list(rbinom(60, 1, 0.5), rbinom(60, 1, 0.5)) p <- plot_MulROC(scores, labels)
Principal component analysis plot
plot_PCA( data, labs, title = "Evaluate the batch effect between groups", palette = "house", font = "Arial", ... )plot_PCA( data, labs, title = "Evaluate the batch effect between groups", palette = "house", font = "Arial", ... )
data |
Matrix or data frame with samples in rows and features in columns. |
labs |
Group labels, one per sample. |
title |
Plot title. |
palette |
Palette name passed to |
font |
Font family used in the plot. |
... |
Passed to |
A ggplot object.
set.seed(1) p <- plot_PCA(matrix(rnorm(200), nrow = 20), rep(c("A", "B"), each = 10))set.seed(1) p <- plot_PCA(matrix(rnorm(200), nrow = 20), rep(c("A", "B"), each = 10))
Precision against recall for a binary outcome. On an imbalanced outcome the ROC curve can look encouraging while precision stays low, which is what this plot exposes: it is the recommended companion when the event is rare.
plot_pr_curve( scores, labels, positive = NULL, palette = "house", title = NULL, font = "Arial", show_auc = TRUE )plot_pr_curve( scores, labels, positive = NULL, palette = "house", title = NULL, font = "Arial", show_auc = TRUE )
scores |
Numeric vector, or a matrix or data frame with one column per marker. |
labels |
Binary outcome, one value per observation. |
positive |
Percentile of the scores above which the positive class is expected. Used only to draw the no-skill reference line, which is the prevalence of the positive class. |
palette |
Palette name passed to |
title |
Plot title. |
font |
Font family used in the plot. |
show_auc |
Print the area under the curve, computed by the trapezoid rule, in the legend. |
A ggplot object.
plot_ROC() for discrimination, plot_calibration() for the level
of the predictions.
set.seed(1) outcome <- rbinom(200, 1, 0.15) score <- outcome * 0.8 + rnorm(200) p <- plot_pr_curve(score, outcome)set.seed(1) outcome <- rbinom(200, 1, 0.15) score <- outcome * 0.8 + rnorm(200) p <- plot_pr_curve(score, outcome)
Plot a risk score ordered by patient
plot_RiskScore( rs, event, legend.position = c(0.2, 0.8), palette = "house", color = NULL, font = "Arial" )plot_RiskScore( rs, event, legend.position = c(0.2, 0.8), palette = "house", color = NULL, font = "Arial" )
rs |
Numeric risk scores. Names, when present, are used as patient identifiers. |
event |
Event indicator used to fill the bars. |
legend.position |
Legend position. |
palette |
Palette name passed to |
color |
Optional vector of fill colours; overrides |
font |
Font family used in the plot. |
A ggplot object.
set.seed(1) p <- plot_RiskScore(rnorm(30), rbinom(30, 1, 0.4))set.seed(1) p <- plot_RiskScore(rnorm(30), rbinom(30, 1, 0.4))
Plots receiver operating characteristic curves with the area under the curve and its confidence interval in the legend.
plot_ROC( scores, labels, force05 = FALSE, palette = "house", legend.pos = "bottom", title = NULL, font = "Arial", percent.style = FALSE )plot_ROC( scores, labels, force05 = FALSE, palette = "house", legend.pos = "bottom", title = NULL, font = "Arial", percent.style = FALSE )
scores |
Numeric vector, or a matrix or data frame with one column per marker. |
labels |
Binary outcome, one value per observation. |
force05 |
Flip markers whose area under the curve is below 0.5 so that every curve is plotted above the diagonal. |
palette |
Palette name passed to |
legend.pos |
Legend position: a position such as |
title |
Plot title. |
font |
Font family used in the plot. |
percent.style |
Label the axes as percentages. |
A ggplot object.
set.seed(1) scores <- cbind(marker1 = rnorm(80), marker2 = rnorm(80)) labels <- rep(c(0, 1), each = 40) p <- plot_ROC(scores, labels)set.seed(1) scores <- cbind(marker1 = rnorm(80), marker2 = rnorm(80)) labels <- rep(c(0, 1), each = 40) p <- plot_ROC(scores, labels)
Plots survival ROC curves at one or more time points using the
Kaplan-Meier method of the survivalROC package.
plot_TimeROC( scores, survival, time_points, groups, palette = "house", legend.pos = "bottom", title = NULL, font = "Arial", percent.style = FALSE )plot_TimeROC( scores, survival, time_points, groups, palette = "house", legend.pos = "bottom", title = NULL, font = "Arial", percent.style = FALSE )
scores |
Numeric marker values. |
survival |
A two-column survival object. |
time_points |
Time points at which the curves are evaluated. |
groups |
Labels for the curves, one per time point. |
palette |
Palette name passed to |
legend.pos |
Legend position: a position such as |
title |
Plot title. |
font |
Font family used in the plot. |
percent.style |
Label the axes as percentages. |
A ggplot object.
if (requireNamespace("survivalROC", quietly = TRUE)) { set.seed(1) surv <- survival::Surv(rexp(100), rbinom(100, 1, 0.6)) p <- plot_TimeROC(rnorm(100), surv, c(1, 2), c("year1", "year2")) }if (requireNamespace("survivalROC", quietly = TRUE)) { set.seed(1) surv <- survival::Surv(rexp(100), rbinom(100, 1, 0.6)) p <- plot_TimeROC(rnorm(100), surv, c(1, 2), c("year1", "year2")) }
t-SNE projection of samples coloured by group
plot_tsne( data, labs, title = "Evaluate the batch effect between groups", perplexity = 30, seed = 1, palette = "house", font = "Arial", ... )plot_tsne( data, labs, title = "Evaluate the batch effect between groups", perplexity = 30, seed = 1, palette = "house", font = "Arial", ... )
data |
Matrix or data frame with samples in rows and features in columns. |
labs |
Group labels, one per sample. |
title |
Plot title. |
perplexity |
Perplexity for the t-SNE embedding. |
seed |
Optional seed; t-SNE is stochastic, so a seed makes a figure reproducible. |
palette |
Palette name passed to |
font |
Font family used in the plot. |
... |
Passed to |
A ggplot object.
if (requireNamespace("Rtsne", quietly = TRUE)) { set.seed(1) p <- plot_tsne(matrix(rnorm(200), nrow = 20), rep(c("A", "B"), each = 10)) }if (requireNamespace("Rtsne", quietly = TRUE)) { set.seed(1) p <- plot_tsne(matrix(rnorm(200), nrow = 20), rep(c("A", "B"), each = 10)) }
UMAP projection plot
plot_UMAP( data, labs, title = "Evaluate the batch effect between groups", palette = "house", font = "Arial", ... )plot_UMAP( data, labs, title = "Evaluate the batch effect between groups", palette = "house", font = "Arial", ... )
data |
Matrix or data frame with samples in rows and features in columns. |
labs |
Group labels, one per sample. |
title |
Plot title. |
palette |
Palette name passed to |
font |
Font family used in the plot. |
... |
Passed to |
A ggplot object.
if (requireNamespace("umap", quietly = TRUE)) { set.seed(1) p <- plot_UMAP(matrix(rnorm(200), nrow = 20), rep(c("A", "B"), each = 10)) }if (requireNamespace("umap", quietly = TRUE)) { set.seed(1) p <- plot_UMAP(matrix(rnorm(200), nrow = 20), rep(c("A", "B"), each = 10)) }
Violin plots with the individual observations overlaid, which shows both the shape of each distribution and how much data stands behind it. A boxplot alone hides a bimodal group and a group with four samples.
plot_violin( value, group, order = NULL, show = c("violin", "box", "both"), points = TRUE, points_maximum = 300, show_n = TRUE, significance = FALSE, palette = "house", ylab = NULL, xlab = NULL, title = NULL, font = "Arial" )plot_violin( value, group, order = NULL, show = c("violin", "box", "both"), points = TRUE, points_maximum = 300, show_n = TRUE, significance = FALSE, palette = "house", ylab = NULL, xlab = NULL, title = NULL, font = "Arial" )
value |
Numeric values. |
group |
Grouping vector, one value per observation. |
order |
Group order. Defaults to the order of the levels, or of first appearance for a plain vector. |
show |
Which to draw: |
points |
Draw the individual observations. |
points_maximum |
Draw the observations only when there are at most
this many, since a violin over thousands of points is unreadable. Use
|
show_n |
Print the number of observations under each group. |
significance |
Add pairwise Wilcoxon comparisons. |
palette |
Palette name passed to |
ylab, xlab, title
|
Axis and plot labels. |
font |
Font family used in the plot. |
A ggplot object.
plot_Boxplot() for the box-only version.
set.seed(1) p <- plot_violin(c(rnorm(40), rnorm(40, 1)), rep(c("A", "B"), each = 40))set.seed(1) p <- plot_violin(c(rnorm(40), rnorm(40, 1)), rep(c("A", "B"), each = 40))
Effect size against significance, with the calling thresholds drawn. This is the standard first look at a differential analysis: it separates the features that moved a lot from the ones that moved reliably, and shows how many of each the thresholds produce.
plot_volcano( effect, p_value, label = NULL, effect_threshold = 1, p_threshold = 0.05, label_top = 10, palette = "house", repel = TRUE, xlab = "Effect size", ylab = expression(-log[10] ~ italic(P)), title = NULL, font = "Arial" )plot_volcano( effect, p_value, label = NULL, effect_threshold = 1, p_threshold = 0.05, label_top = 10, palette = "house", repel = TRUE, xlab = "Effect size", ylab = expression(-log[10] ~ italic(P)), title = NULL, font = "Arial" )
effect |
Numeric effect sizes, typically a log fold change. |
p_value |
Significance values on the same scale as |
label |
Feature labels. |
effect_threshold, p_threshold
|
Calling thresholds. Features past both are labelled as significant. |
label_top |
Label the most significant features instead of every
significant one. Set to |
palette |
Palette name passed to |
repel |
Repel the labels so they do not overlap. |
xlab, ylab, title
|
Axis and plot labels. |
font |
Font family used in the plot. |
A ggplot object.
set.seed(1) effect <- rnorm(2000) p_value <- runif(2000)^2 p <- plot_volcano(effect, p_value, paste0("gene", seq_along(effect)))set.seed(1) effect <- rnorm(2000) p_value <- runif(2000)^2 p <- plot_volcano(effect, p_value, paste0("gene", seq_along(effect)))
Patients ranked by response, with the bar height showing how far each departed from baseline and the fill showing the response category. This is the standard display of response in a single-arm trial.
plot_waterfall( response, category = NULL, patient = NULL, label_top = 0, thresholds = c(`Partial response` = -30, `Stable disease` = 20), threshold_labels = TRUE, show_patients = FALSE, palette = "house", xlab = NULL, ylab = "Change from baseline (%)", title = NULL, font = "Arial" )plot_waterfall( response, category = NULL, patient = NULL, label_top = 0, thresholds = c(`Partial response` = -30, `Stable disease` = 20), threshold_labels = TRUE, show_patients = FALSE, palette = "house", xlab = NULL, ylab = "Change from baseline (%)", title = NULL, font = "Arial" )
response |
Numeric response values, for example a percentage change
from baseline. |
category |
Optional response category per patient, used to fill the bars. Defaults to the RECIST-style cut-offs, where -30 and 20 percent separate partial response, stable disease, and progression. |
patient |
Optional patient labels, used on the x axis when few enough bars are drawn to read them. |
label_top |
Label this many of the largest and smallest bars, which is what a reader wants from a dense waterfall. |
thresholds |
Cut-offs between response categories, as a named vector
such as |
threshold_labels |
Print the cut-off lines and their values. |
show_patients |
Print patient labels under the bars. |
palette |
Palette name passed to |
xlab, ylab, title
|
Axis and plot labels. |
font |
Font family used in the plot. |
A ggplot object.
set.seed(1) response <- c(rnorm(40, -10, 20), rnorm(10, 40, 15)) p <- plot_waterfall(response)set.seed(1) response <- c(rnorm(40, -10, 20), rnorm(10, 40, 15)) p <- plot_waterfall(response)
Updated version of the viewGSEA() helper distributed with
HTSanalyzeR2.
viewGSEA(object, gscName, gsName, title = "")viewGSEA(object, gscName, gsName, title = "")
object |
An |
gscName |
Name of the gene set collection. |
gsName |
Name of the gene set. |
title |
Plot title. |
A ggplot object.