## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>",
    fig.align = "center",
    # The vignette is HTML, so htmlwidgets embed natively; disable knitr's
    # PhantomJS / webshot screenshot fallback so no extra system dep is
    # needed to build the vignette.
    screenshot.force = FALSE
)

## ----install, eval = FALSE----------------------------------------------------
# # (chunk intentionally not run during knit)
# # From GitHub
# remotes::install_github("george123ya/reglScatterplotR")
# 
# # Once accepted into Bioconductor
# if (!requireNamespace("BiocManager", quietly = TRUE)) {
#     install.packages("BiocManager")
# }
# BiocManager::install("reglScatterplotR")

## ----library------------------------------------------------------------------
library(reglScatterplotR)

## ----basic--------------------------------------------------------------------
set.seed(1L)
df <- data.frame(
    x = rnorm(20000),
    y = rnorm(20000),
    cluster = sample(letters[1:6], 20000, replace = TRUE),
    score = runif(20000)
)

reglScatterplot(df, x = "x", y = "y")

## ----categorical--------------------------------------------------------------
reglScatterplot(df,
    x = "x", y = "y", colorBy = "cluster",
    legendTitle = "Cluster"
)

## ----continuous---------------------------------------------------------------
reglScatterplot(df,
    x = "x", y = "y", colorBy = "score",
    continuousPalette = "magma",
    vmin = "p1", vmax = "p99"
)

## ----sce----------------------------------------------------------------------
library(SingleCellExperiment)
data(reglScatterExample)
ex <- reglScatterExample
sce <- SingleCellExperiment(
    assays = list(logcounts = t(as.matrix(ex["CD3D"]))),
    colData = ex[, c("celltype", "nCount", "percentMito")],
    reducedDims = list(UMAP = as.matrix(ex[, c("UMAP_1", "UMAP_2")]))
)
sce
reglScatterplot(sce, x = "UMAP", colorBy = "celltype")

## ----sce-gene-----------------------------------------------------------------
reglScatterplot(sce, x = "UMAP", colorBy = "CD3D", vmax = "p99")

## ----spe, eval = FALSE--------------------------------------------------------
# reglScatterplot(spe, x = "spatial", colorBy = "celltype")

## ----sync, eval = FALSE-------------------------------------------------------
# library(shiny)
# ui <- fluidPage(
#     fluidRow(
#         column(6, reglScatterplotOutput("plotA")),
#         column(6, reglScatterplotOutput("plotB"))
#     ),
#     actionButton("link", "Link cameras")
# )
# server <- function(input, output, session) {
#     output$plotA <- renderReglScatterplot({
#         reglScatterplot(df,
#             x = "x", y = "y", colorBy = "cluster",
#             plotId = "plotA"
#         )
#     })
#     output$plotB <- renderReglScatterplot({
#         reglScatterplot(df,
#             x = "x", y = "y", colorBy = "score",
#             plotId = "plotB"
#         )
#     })
#     observeEvent(input$link, {
#         enableReglScatterplotSync(c("plotA", "plotB"))
#     })
# }
# shinyApp(ui, server)

## ----sessionInfo, eval = TRUE-------------------------------------------------
sessionInfo()

