SVG Plots
14 functions for publication-quality SVG and PNG plots. All return an svg value that can be saved, displayed inline, or embedded in HTML reports.
Common Options
| Option | Type | Default | Description |
|---|---|---|---|
| width | int | 800 | Plot width in pixels |
| height | int | 600 | Plot height in pixels |
| title | string | "" | Plot title |
| x_label | string | "" | X-axis label |
| y_label | string | "" | Y-axis label |
| color | string | "#8b5cf6" | Primary color (hex or named) |
| palette | string | "viridis" | Color palette name |
| theme | string | "dark" | "dark" or "light" |
plot
Generic plot dispatcher. Accepts data and a type option to select the chart kind.
plot(data, opts?) -> svg
plot([1, 4, 9, 16, 25], {type: "line", title: "Squares"})
plot({"A": 30, "T": 25, "C": 28, "G": 27}, {type: "bar"})
scatter
Scatter plot with optional color and size mapping.
scatter(data, opts?) -> svg
let expr = csv("expression.csv")
scatter(expr, {
x: "control_mean",
y: "treated_mean",
color: "significant",
title: "Control vs Treated Expression",
x_label: "Control (TPM)",
y_label: "Treated (TPM)"
}) |> save_svg("scatter.svg")
Output
heatmap
Heatmap from matrix or table data. Supports clustering and dendrograms.
heatmap(mat, opts?) -> svg
let expr_matrix = matrix([
[10.2, 8.5, 12.1, 9.8],
[5.3, 4.8, 5.9, 5.1],
[20.1, 18.7, 22.3, 19.5]
])
heatmap(expr_matrix, {
row_labels: ["BRCA1", "TP53", "EGFR"],
col_labels: ["S1", "S2", "S3", "S4"],
palette: "viridis",
cluster_rows: true,
cluster_cols: true,
title: "Gene Expression Heatmap"
}) |> save_svg("heatmap.svg")
Output
histogram
histogram(data, opts?) -> svg # continuous data, binned
histogram(quality_scores, {bins: 30, title: "Quality Score Distribution"})
Output
violin
violin(groups, opts?) -> svg
let groups = {
"WT": [30, 32, 28, 35, 31],
"KO": [22, 25, 20, 18, 24],
"OE": [40, 38, 42, 45, 41]
}
violin(groups, {title: "Expression Distribution"})
volcano / ma_plot
Standard differential expression visualizations.
volcano(tbl, opts?) -> svg
ma_plot(tbl, opts?) -> svg
let de = csv("deseq2_results.csv")
volcano(de, {
x: "log2FoldChange",
y: "padj",
fc_threshold: 1.0,
p_threshold: 0.05,
label_top: 10,
title: "Differential Expression"
}) |> save_svg("volcano.svg")
Output
ma_plot(de, {
x: "baseMean",
y: "log2FoldChange",
color: "padj",
title: "MA Plot"
})
save_svg
save_svg(svg, path) -> string
let p = scatter(data, {title: "My Plot"})
save_svg(p, "plot.svg")
Additional Plot Types
| Function | Description |
|---|---|
| density(data, opts?) | Kernel density estimation plot |
| genome_track(data, opts?) | Genome annotation track (genes, exons, introns) |