## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## ----load, message = FALSE----------------------------------------------------
library(CanvasXpressBio)
library(SummarizedExperiment)

## ----dataset------------------------------------------------------------------
se <- makeDemoSE()
se

## ----heatmap------------------------------------------------------------------
cxplot(se, title = "Marker-gene expression",
    overlays = c("Cohort", "Condition"), var_overlays = "Direction",
    cluster = TRUE)

## ----volcano------------------------------------------------------------------
res <- S4Vectors::metadata(se)$deResults
cxvolcano(res, title = "Week 12 vs baseline",
    label_genes = rownames(se))

## ----km-----------------------------------------------------------------------
baseline_se <- se[, se$Condition == "Baseline"]
cxsurvival(baseline_se, time = "Time", status = "Status", group = "Cohort",
    tooltip = c("Patient", "updown"),
    kmCensoredRug = TRUE, kmPvalue = TRUE,
    title = "Survival by cohort")

## ----boxplot------------------------------------------------------------------
paired <- S4Vectors::metadata(se)$albPaired
ptext  <- function(p) if (p < 1e-4) "p<0.0001" else sprintf("p=%.3g", p)
ytop   <- max(assay(se)["ALB", ]) + 0.3

cxboxplot(se, feature = "ALB", group = "Condition", segregate = "Cohort",
    connect = "Patient", color = "updown",
    title = "ALB over time, per patient",
    colorKey = list(updown = list(
        up = "rgb(224,130,20)",
        down = "rgb(58,102,160)")),
    decorations = list(text = list(
        list(value = ytop, label = ptext(paired[["Cohort A"]]), panel = 1,
            smpCenter = TRUE, preTransformed = TRUE),
        list(value = ytop, label = ptext(paired[["Cohort B"]]), panel = 2,
            smpCenter = TRUE, preTransformed = TRUE))))

## ----beeswarm-----------------------------------------------------------------
bse <- makeBeeswarmDemo(n_per_group = 500)
cxboxplot(bse, feature = "Expression", group = "Group", color = "Group",
    points = "sina", showLegend = FALSE,
    title = "Beeswarm overlay with 2,500 points")

## ----sessioninfo--------------------------------------------------------------
sessionInfo()

