create_view: Create a custom view

View source: R/view-composers.R

create_viewR Documentation

Create a custom view

Description

Create a custom view from a data.frame or a tibble.

Usage

create_view(name, data, abbrev = name)

Arguments

name

Name of the view. A character vector.

data

A data.frame or a tibble with named variables in columns and rows for each spatial unit ordered as in the intraview.

abbrev

Abbreviated name. A character vector.

Details

Creating a custom view does not add it to the current view composition.

Value

A new mistyR view. A list with a single named item described by the provided abbreviation and data containing the provided data.

See Also

add_views() for adding created views to a view composition.

Other view composition functions: add_juxtaview(), add_paraview(), add_views(), create_initial_view(), remove_views()

Examples

# Create a view from the mean expression of the 10 nearest neighbors of
# each cell.

library(dplyr)
library(purrr)
library(distances)

# get the expression data
data("synthetic")
expr <- synthetic[[1]] %>% select(-c(row, col, type))
# get the coordinates for each cell
pos <- synthetic[[1]] %>% select(row, col)

# find the 10 nearest neighbors
neighbors <- nearest_neighbor_search(distances(as.matrix(pos)), k = 11)[-1, ]

# calculate the mean expression of the nearest neighbors for all markers
# for each cell in expr
nnexpr <- seq_len(nrow(expr)) %>%
  map_dfr(~ expr %>%
    slice(neighbors[, .x]) %>%
    colMeans())

create_view("nearest", nnexpr, "nn")

saezlab/misty documentation built on March 25, 2024, 4:11 p.m.