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

OptionTypeDefaultDescription
widthint800Plot width in pixels
heightint600Plot height in pixels
titlestring""Plot title
x_labelstring""X-axis label
y_labelstring""Y-axis label
colorstring"#8b5cf6"Primary color (hex or named)
palettestring"viridis"Color palette name
themestring"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
Control vs Treated Expression Control (TPM) Treated (TPM) 0 25 50 75 100 0 25 50 75 100 Not significant Significant

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
Gene Expression Heatmap S1 S2 S3 S4 BRCA1 TP53 EGFR 10.2 8.5 12.1 9.8 5.3 4.8 5.9 5.1 20.1 18.7 22.3 19.5 Low High

histogram

histogram(data, opts?) -> svg     # continuous data, binned
histogram(quality_scores, {bins: 30, title: "Quality Score Distribution"})
Output
Variants by Region 0 12k 24k 36k 48k 12,500 45,000 3,200 8,900 Exon Intron UTR Intergenic

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
Differential Expression log2(Fold Change) -log10(p-value) -4 -2 0 2 4 0 5 10 15 p=0.05 EGFR BRCA1 MYC TP53
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

FunctionDescription
density(data, opts?)Kernel density estimation plot
genome_track(data, opts?)Genome annotation track (genes, exons, introns)