View source: R/utility_functions.R
getDensity | R Documentation |
Get local density (z) of bivariate relationship (x,y)
getDensity(x, y, ...)
x |
numeric (equal length as y) |
y |
numeric |
... |
additional parameters passed to MASS::kde2d |
density values
Nicholas Mikolajewicz
Kamil Slowikowski (https://slowkow.com/notes/ggplot2-color-by-density/)
# get data and compute densities
df.meta <- so@meta.data # so is seurat object
df.meta$density1 <- getDensity(df.meta$nCount_RNA, df.meta$percent.mt, n = 100)
# generate scatter plot with overlayed density values
plt.handle1 <- df.meta %>% ggplot(aes(x = nCount_RNA, y = percent.mt, color = density1)) + geom_point() + theme_miko(legend = T) +
xlab("UMI/cell") + ylab("Mitochondrial Content (%)") +
labs(title = paste0("r = ", rho1p, "; rho = ", rho1s)) + scale_color_viridis("Density") +
theme(legend.position="bottom", legend.key.width=unit(legend.width,"cm"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.