Create a custom view from a data.frame
or a tibble
.
Arguments
- name
Name of the view. A character vector.
- data
A
data.frame
or atibble
with named variables in columns and rows for each spatial unit ordered as in the intraview.- abbrev
Abbreviated name. A character vector.
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")
#> $nearest
#> $nearest$abbrev
#> [1] "nn"
#>
#> $nearest$data
#> # A tibble: 4,205 × 11
#> ECM ligA ligB ligC ligD protE protF prodA prodB prodC prodD
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.169 0.449 0.0349 0.242 0.619 0.337 1.07 0.120 0.0138 0.146 0.165
#> 2 0.346 0.223 0.0303 0.478 0.191 0.676 0.549 0.0969 0.0140 0.190 0.0766
#> 3 0.219 0.242 0.0375 0.456 0.218 0.304 0.495 0.0496 0.0288 0.236 0.0387
#> 4 0.238 0.312 0.0433 0.311 0.303 0.607 0.651 0.132 0.0288 0.0954 0.122
#> 5 0.313 0.341 0.0480 0.269 0.357 0.688 0.835 0.166 0.0297 0.0837 0.173
#> 6 0.527 0.257 0.0668 0.369 0.346 0.743 0.616 0.0722 0.0184 0.135 0.0964
#> 7 0.278 0.241 0.0952 0.480 0.347 0.399 0.501 0.0413 0.0632 0.160 0.0604
#> 8 0.266 0.260 0.0912 0.444 0.385 0.537 0.624 0.0738 0.0463 0.154 0.117
#> 9 0.356 0.210 0.0811 0.522 0.311 0.564 0.565 0.0696 0.0415 0.208 0.106
#> 10 0.625 0.152 0.0923 0.612 0.229 0.863 0.458 0.0350 0.0823 0.230 0.0576
#> # ℹ 4,195 more rows
#>
#>