Skip to contents

[Experimental]

This function is a wrapper around layout_with_pmds from the graphlayouts R package, and can be used to compute a pmds layout of a graph with edge weights.

Usage

layout_with_weighted_pmds(
  g,
  dim = 2,
  method = c("prob_dist", "cos_dist"),
  pivots = 200,
  pow = 3,
  seed = 123
)

Arguments

g

An igraph or a tbl_graph object

dim

Desired number of dimensions. Can be 2 or 3

method

Edge weighting method to use for computing the layout. Can be either "prob_dist" or "cos_dist".

pivots

Number of pivots

pow

Power to raise the distance weights to. Increasing this value will amplify higher distance weights. Default is 3.

seed

Set seed for pivot sampling

Value

A matrix of 2D or 3D coordinates

weights

Examples

library(dplyr)

pxl_file <- system.file("extdata/five_cells",
                        "five_cells.pxl",
                        package = "pixelatorR")
seur_obj <- ReadMPX_Seurat(pxl_file) %>%
  LoadCellGraphs(cells = colnames(.)[1])
#>  Created a 'Seurat' object with 5 cells and 80 targeted surface proteins
#> →    Loading CellGraphs for 1 cells from sample 1
#>  Successfully loaded 1 CellGraph object(s).

# compute weighted pMDS layout
g <- CellGraphs(seur_obj)[[1]] %>%
  CellGraphData("cellgraph")
layout <- layout_with_weighted_pmds(g, dim = 3) %>%
  as_tibble(.name_repair = ~c("x", "y", "z"))
plotly::plot_ly(
  layout,
  x = ~x,
  y = ~y,
  z = ~z,
  size = 1,
  type = "scatter3d",
  mode = "markers"
)
# or using ComputeLayout and Plot3DGraph seur_obj <- seur_obj %>% # Compute weighted pMDS layout ComputeLayout(layout_method = "wpmds", dim = 3) #> Computing layouts for 1 graphs # Create 3D plot Plot3DGraph(seur_obj, layout_method = "wpmds", cell_id = colnames(seur_obj)[1], marker = "CD3E")