Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raster.dpi param for geom_scattermore (updated branch) #5392

Merged
merged 5 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Seurat
Version: 4.0.6
Version: 4.0.6.9001
Date: 2021-12-16
Title: Tools for Single Cell Genomics
Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) <doi:10.1038/nbt.3192>, Macosko E, Basu A, Satija R, et al (2015) <doi:10.1016/j.cell.2015.05.002>, Stuart T, Butler A, et al (2019) <doi:10.1016/j.cell.2019.05.031>, and Hao, Hao, et al (2020) <doi:10.1101/2020.10.12.335331> for more details.
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased
## Added
- Add `raster.dpi` parameter to `DimPlot/FeaturePlot` to optionally rasterize individual points ([#5392](https://github.com/satijalab/seurat/pull/5392))


# Seurat 4.0.6 (2021-12-16)
## Added

Expand Down
54 changes: 42 additions & 12 deletions R/visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ ColorDimSplit <- function(
#' ggplot object. If \code{FALSE}, return a list of ggplot objects
#' @param raster Convert points to raster format, default is \code{NULL} which
#' automatically rasterizes if plotting more than 100,000 cells
#' @param raster.dpi Pixel resolution for rasterized plots, passed to geom_scattermore().
#' Default is c(512, 512).
#'
#' @return A \code{\link[patchwork]{patchwork}ed} ggplot object if
#' \code{combine = TRUE}; otherwise, a list of ggplot objects
Expand Down Expand Up @@ -806,7 +808,8 @@ DimPlot <- function(
na.value = 'grey50',
ncol = NULL,
combine = TRUE,
raster = NULL
raster = NULL,
raster.dpi = c(512, 512)
) {
if (length(x = dims) != 2) {
stop("'dims' must be a two-length vector")
Expand Down Expand Up @@ -853,7 +856,8 @@ DimPlot <- function(
cols.highlight = cols.highlight,
sizes.highlight = sizes.highlight,
na.value = na.value,
raster = raster
raster = raster,
raster.dpi = raster.dpi
)
if (label) {
plot <- LabelClusters(
Expand Down Expand Up @@ -995,7 +999,8 @@ FeaturePlot <- function(
sort.cell = NULL,
interactive = FALSE,
combine = TRUE,
raster = NULL
raster = NULL,
raster.dpi = c(512, 512)
) {
# TODO: deprecate fully on 3.2.0
if (!is.null(x = sort.cell)) {
Expand Down Expand Up @@ -1257,7 +1262,8 @@ FeaturePlot <- function(
cols = cols.use,
shape.by = shape.by,
label = FALSE,
raster = raster
raster = raster,
raster.dpi = raster.dpi
) +
scale_x_continuous(limits = xlims) +
scale_y_continuous(limits = ylims) +
Expand Down Expand Up @@ -1833,7 +1839,8 @@ CellScatter <- function(
cols = NULL,
pt.size = 1,
smooth = FALSE,
raster = NULL
raster = NULL,
raster.dpi = c(512, 512)
) {
features <- features %||% rownames(x = object)
data <- FetchData(
Expand All @@ -1848,7 +1855,8 @@ CellScatter <- function(
pt.size = pt.size,
rows.highlight = highlight,
smooth = smooth,
raster = raster
raster = raster,
raster.dpi = raster.dpi
)
return(plot)
}
Expand Down Expand Up @@ -1880,6 +1888,8 @@ CellScatter <- function(
#' @param raster Convert points to raster format, default is \code{NULL}
#' which will automatically use raster if the number of points plotted is greater than
#' 100,000
#' @param raster.dpi Pixel resolution for rasterized plots, passed to geom_scattermore().
#' Default is c(512, 512).
#' @param jitter Jitter for easier visualization of crowded points
#'
#' @return A ggplot object
Expand Down Expand Up @@ -1913,6 +1923,7 @@ FeatureScatter <- function(
slot = 'data',
plot.cor = TRUE,
raster = NULL,
raster.dpi = c(512, 512),
jitter = TRUE
) {
cells <- cells %||% colnames(x = object)
Expand Down Expand Up @@ -1955,6 +1966,7 @@ FeatureScatter <- function(
span = span,
plot.cor = plot.cor,
raster = raster,
raster.dpi = raster.dpi,
jitter = jitter
)
}
Expand Down Expand Up @@ -2000,7 +2012,8 @@ VariableFeaturePlot <- function(
log = NULL,
selection.method = NULL,
assay = NULL,
raster = NULL
raster = NULL,
raster.dpi = c(512, 512)
) {
if (length(x = cols) != 2) {
stop("'cols' must be of length 2")
Expand Down Expand Up @@ -2034,7 +2047,8 @@ VariableFeaturePlot <- function(
data = hvf.info,
col.by = var.status,
pt.size = pt.size,
raster = raster
raster = raster,
raster.dpi = raster.dpi
)
if (length(x = unique(x = var.status)) == 1) {
switch(
Expand Down Expand Up @@ -6792,6 +6806,8 @@ globalVariables(names = '..density..', package = 'Seurat')
#' @param raster Convert points to raster format, default is \code{NULL}
#' which will automatically use raster if the number of points plotted is
#' greater than 100,000
#' @param raster.dpi the pixel resolution for rastered plots, passed to geom_scattermore().
#' Default is c(512, 512)
#' @param plot.cor ...
#' @param jitter Jitter for easier visualization of crowded points
#'
Expand Down Expand Up @@ -6819,6 +6835,7 @@ SingleCorPlot <- function(
na.value = 'grey50',
span = NULL,
raster = NULL,
raster.dpi = NULL,
plot.cor = TRUE,
jitter = TRUE
) {
Expand All @@ -6828,6 +6845,10 @@ SingleCorPlot <- function(
"\nTo disable this behavior set `raster=FALSE`")
}
raster <- raster %||% (nrow(x = data) > 1e5)
if (!is.null(x = raster.dpi)) {
if (!is.numeric(x = raster.dpi) || length(x = raster.dpi) != 2)
stop("'raster.dpi' must be a two-length numeric vector")
}
orig.names <- colnames(x = data)
names.plot <- colnames(x = data) <- gsub(
pattern = '-',
Expand Down Expand Up @@ -6923,7 +6944,8 @@ SingleCorPlot <- function(
plot <- plot + geom_scattermore(
mapping = aes_string(color = 'colors'),
position = position,
pointsize = pt.size
pointsize = pt.size,
pixels = raster.dpi
)
} else {
plot <- plot + geom_point(
Expand All @@ -6934,7 +6956,7 @@ SingleCorPlot <- function(
}
} else {
if (raster) {
plot <- plot + geom_scattermore(position = position, pointsize = pt.size)
plot <- plot + geom_scattermore(position = position, pointsize = pt.size, pixels = raster.dpi)
} else {
plot <- plot + geom_point(position = position, size = pt.size)
}
Expand Down Expand Up @@ -6994,6 +7016,8 @@ SingleCorPlot <- function(
#' @param raster Convert points to raster format, default is \code{NULL}
#' which will automatically use raster if the number of points plotted is
#' greater than 100,000
#' @param raster.dpi the pixel resolution for rastered plots, passed to geom_scattermore().
#' Default is c(512, 512)
#'
#' @return A ggplot2 object
#'
Expand Down Expand Up @@ -7022,14 +7046,19 @@ SingleDimPlot <- function(
cols.highlight = '#DE2D26',
sizes.highlight = 1,
na.value = 'grey50',
raster = NULL
raster = NULL,
raster.dpi = NULL
) {
pt.size <- pt.size %||% AutoPointSize(data = data, raster = raster)
if ((nrow(x = data) > 1e5) & !isFALSE(raster)){
message("Rasterizing points since number of points exceeds 100,000.",
"\nTo disable this behavior set `raster=FALSE`")
}
raster <- raster %||% (nrow(x = data) > 1e5)
if (!is.null(x = raster.dpi)) {
if (!is.numeric(x = raster.dpi) || length(x = raster.dpi) != 2)
stop("'raster.dpi' must be a two-length numeric vector")
}
if (length(x = dims) != 2) {
stop("'dims' must be a two-length vector")
}
Expand Down Expand Up @@ -7113,7 +7142,8 @@ SingleDimPlot <- function(
shape = shape.by,
alpha = alpha.by
),
pointsize = pt.size
pointsize = pt.size,
pixels = raster.dpi
)
} else {
plot + geom_point(
Expand Down
6 changes: 5 additions & 1 deletion man/CellScatter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/ColorDimSplit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/DimPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/FeaturePlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/FeatureScatter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/SingleCorPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/SingleDimPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/VariableFeaturePlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed src/stats.o
Binary file not shown.