Extract hexagonal bin centroids and related information from non-linear dimensionality reduction data.
Source:R/2D.R
extract_hexbin_centroids.Rd
Extract hexagonal bin centroids and related information from non-linear dimensionality reduction data.
Arguments
- nldr_df
A data frame containing 2D embeddings.
- num_bins
Number of bins along the x-axis for hexagon binning.
- shape_val
The value of the shape parameter for hexagon binning.
- x
The name of the column that contains first 2D embeddings component.
- y
The name of the column that contains second 2D embeddings component.
Examples
# Example usage of extract_hexbin_centroids function
num_bins_x <- 4
shape_value <- 1.833091
result <- extract_hexbin_centroids(nldr_df = s_curve_noise_umap,
num_bins = num_bins_x, shape_val = shape_value, x = "UMAP1", y = "UMAP2")
hexdf_data <- result$hexdf_data
hb_data <- result$hb_data
print(hexdf_data)
#> # A tibble: 16 × 5
#> x y hexID counts std_counts
#> <dbl> <dbl> <int> <int> <dbl>
#> 1 -3.27 -5.74 1 2 0.222
#> 2 -1.84 -5.74 2 6 0.667
#> 3 -2.55 -4.38 6 7 0.778
#> 4 -1.12 -4.38 7 5 0.556
#> 5 -3.27 -3.01 11 2 0.222
#> 6 -1.84 -3.01 12 2 0.222
#> 7 -0.407 -3.01 13 2 0.222
#> 8 -1.12 -1.65 17 1 0.111
#> 9 0.308 -1.65 18 8 0.889
#> 10 1.02 -0.280 24 7 0.778
#> 11 0.308 1.09 28 1 0.111
#> 12 1.74 1.09 29 6 0.667
#> 13 0.308 3.82 38 2 0.222
#> 14 1.74 3.82 39 8 0.889
#> 15 1.02 5.18 44 9 1
#> 16 2.46 5.18 45 7 0.778
print(str(hb_data))
#> Formal class 'hexbin' [package "hexbin"] with 16 slots
#> ..@ cell : int [1:16] 1 2 6 7 11 12 13 17 18 24 ...
#> ..@ count : int [1:16] 2 6 7 5 2 2 2 1 8 7 ...
#> ..@ xcm : num [1:16] -2.71 -2.21 -2.82 -1.44 -3.03 ...
#> ..@ ycm : num [1:16] -5.38 -5.52 -4.2 -4.32 -3.66 ...
#> ..@ xbins : num 4
#> ..@ shape : num 1.83
#> ..@ xbnds : num [1:2] -3.27 2.46
#> ..@ ybnds : num [1:2] -5.74 5.82
#> ..@ dimen : num [1:2] 10 5
#> ..@ n : int 75
#> ..@ ncells: int 16
#> ..@ call : language hexbin::hexbin(x = dplyr::pull(nldr_df, { { ...
#> ..@ xlab : chr [1:5] "dplyr::pull(nldr_df, {" " {" " x" " }" ...
#> ..@ ylab : chr [1:5] "dplyr::pull(nldr_df, {" " {" " y" " }" ...
#> ..@ cID : int [1:75] 6 24 29 2 12 44 24 18 24 45 ...
#> ..@ cAtt : int(0)
#> NULL