create_view {mistyR} | R 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 `name`d item described by the provided `abbrev`iation 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")

[Package mistyR version 1.0.3 Index]