Skip to content

Commit

Permalink
Merge branch 'main' into website
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed Nov 8, 2024
2 parents b21fc90 + 203613d commit b3e838e
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 102 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GiottoVisuals
Title: Visuals for the Giotto spatial biology analysis ecosystem
Version: 0.2.6
Version: 0.2.7
Authors@R: c(
person("Ruben", "Dries", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7650-7754")),
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# GiottoVisuals 0.2.7 (2024/11/08)

## enhancements
- scattermore plotting for `spatPlot2D()` and `spatFeatPlot2D()`

## bug fixes
- fix color scaling bug for `spatFeatPlot2D()` introduced in 0.2.6

# GiottoVisuals 0.2.6 (2024/10/27)

## new
Expand Down
48 changes: 38 additions & 10 deletions R/aux_visuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,24 @@ gg_input <- function(ggobject) {

#' @title giotto_point
#' @name giotto_point
#' @description Plot a point scatter layer via one of ggplot::geom_point,
#' scattermore::geom_scattermore or scattermore::geom_scattermost
#' @param plot_method which scatter plotting method to use.
#' @param size point size parameter
#' @param ext SpatVector. Spatial extent of the plotting region. Used when
#' considering raster size for rasterization with scattermore and scattermost
#' @param scattermost_xy 2-column object with data. Used with scattermost since
#' it doesn't talk to ggplot
#' @param scattermost_color Color vector (or a single color). Used with
#' scattermost since it doesn't talk to ggplot
#' @param \dots geom_point parameters
#' @keywords internal
#' @description uses ggplot::geom_point, scattermore::geom_scattermore
#' or scattermore::geom_scattermost
#' @noRd
#' @returns ggplot2::geom_point layer
#'
giotto_point <- function(
plot_method = c("ggplot", "scattermore", "scattermost"),
size = 1,
ext,
scattermost_xy = NULL,
scattermost_color = NULL,
...) {
Expand All @@ -180,21 +189,40 @@ giotto_point <- function(
choices = c("ggplot", "scattermore", "scattermost")
)

px <- getOption("giotto.plot_point_raster", 5e5)
if (!missing(ext)) {
edim <- setNames(range(ext), NULL)
ext_area <- prod(edim)
px_per_unit <- px / ext_area
pixels <- ceiling(edim * sqrt(px_per_unit))
} else {
pixels <- rep(ceiling(sqrt(px)), 2L)
}

# assemble argslist
a <- list(...)

if (plot_method %in% c("scattermore", "scattermost")) {
a$pointsize <- size
a$pixels <- pixels
} else {
a$size <- size
}

# dispatch to plot method
switch(plot_method,
"ggplot" = {
ggplot2::geom_point(size = size, ...)
do.call(ggplot2::geom_point, a)
},
"scattermore" = {
package_check(pkg_name = "scattermore", repository = "CRAN")
scattermore::geom_scattermore(pointsize = size, ...)
do.call(scattermore::geom_scattermore, a)
},
"scattermost" = {
package_check(pkg_name = "scattermore", repository = "CRAN")
scattermore::geom_scattermost(
xy = scattermost_xy,
color = scattermost_color,
pointsize = size
)
a$xy <- scattermost_xy
a$color <- scattermost_color
do.call(scattermore::geom_scattermost, a)
}
)
}
Expand Down
Loading

0 comments on commit b3e838e

Please sign in to comment.