Skip to content
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,7 +1,7 @@
Type: Package
Package: see
Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2'
Version: 0.13.0.3
Version: 0.13.0.4
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ export(flat_colors)
export(geom_binomdensity)
export(geom_count2)
export(geom_count_borderless)
export(geom_count_halo)
export(geom_from_list)
export(geom_jitter2)
export(geom_jitter_borderless)
export(geom_jitter_halo)
export(geom_point2)
export(geom_point_borderless)
export(geom_point_halo)
export(geom_pointrange2)
export(geom_pointrange_borderless)
export(geom_pointrange_halo)
export(geom_pooljitter)
export(geom_poolpoint)
export(geom_violindot)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
* Updated plot-method for `performance::check_model()` for Bayesian ordinal
models.

* New `geom_point_halo()`, `geom_pointrange_halo()`, `geom_jitter_halo()` and
`geom_count_halo()` geoms, which add a slight contour around the points

## Bug fixes

* Fixed the `*_borderless` aliases for `geom_point2()` or `geom_jitter2()`, which

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Typo in the function name alias: *_borless should be *_borderless.

Suggested change
* Fixed the `*_borderless` aliases for `geom_point2()` or `geom_jitter2()`, which
* Fixed the `*_borderless` aliases for `geom_point2()` or `geom_jitter2()`, which

were broken and did not render as intended.

# see 0.13.0

## Breaking Changes
Expand Down
98 changes: 74 additions & 24 deletions R/geom_point2.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#' Better looking points
#' @title Better looking points
#' @name geom_point2
#'
#' Somewhat nicer points (especially in case of transparency) without outline
#' strokes (borders, contours) by default.
#' @description
#' The `*_borderless` geoms (and their shortcuts ending in `2`, such as `geom_point2`
#' or `geom_point_borderless`) render points without an outline stroke by default.
#' This prevents harsh edges and yields a smoother, cleaner look, especially when
#' using transparency.
#'
#' In contrast, the `*_halo` variants feature a border that automatically matches
#' the plot's background color. This creates a subtle visual separation (a "halo"
#' effect) that keeps overlapping points distinct.
#'
#' @param size Size of points.
#' @param stroke Stroke thickness.
#' @param shape Shape of points.
#' @param ... Other arguments to be passed to
#' [ggplot2::geom_point()],
#' [ggplot2::geom_jitter()],
#' [ggplot2::geom_pointrange()], or
#' [ggplot2::geom_count()].
#' @param ... Other arguments to be passed to [ggplot2::geom_point()],
#' [ggplot2::geom_jitter()], [ggplot2::geom_pointrange()], or
#' [ggplot2::geom_count()].
#'
#' @note The color aesthetics for `geom_point_borderless()` is `"fill"`, not
#' `"color"`. See 'Examples'.
#' @note The color aesthetics for the `*_halo()` functions is `"fill"`, not
#' `"color"`. See 'Examples'.
#'
#' @examplesIf requireNamespace("patchwork", quietly = TRUE)
#' library(ggplot2)
Expand All @@ -29,13 +35,18 @@
#'
#' plots(normal, new, n_columns = 2)
#'
#' ggplot(iris, aes(x = Petal.Width, y = Sepal.Length, fill = Species)) +
#' ggplot(iris, aes(x = Petal.Width, y = Sepal.Length, color = Species)) +
#' geom_point_borderless(size = 4) +
#' theme_modern()
#'
#' theme_set(theme_abyss())
#' ggplot(iris, aes(x = Petal.Width, y = Sepal.Length, fill = Species)) +
#' ggplot(iris, aes(x = Petal.Width, y = Sepal.Length, color = Species)) +
#' geom_point_borderless(size = 4)
#'
#' # add "halo" effect - note that the aesthetics is "fill", not "color"
#' theme_set(theme_abyss())
#' ggplot(iris, aes(x = Petal.Width, y = Sepal.Length, fill = Species)) +
#' geom_point_halo(size = 12)
#' @export
geom_point2 <- function(..., stroke = 0, shape = 16) {
geom_point(stroke = stroke, shape = shape, ...)
Expand Down Expand Up @@ -66,36 +77,75 @@ geom_count_borderless <- geom_count2

#' @rdname geom_point2
#' @export
geom_point_borderless <- function(...) {
geom_point(pch = 21, color = .get_theme_bg_color(), ...)
geom_point_borderless <- geom_point2


#' @rdname geom_point2
#' @export
geom_jitter_borderless <- geom_jitter2


#' @rdname geom_point2
#' @export
geom_pointrange_borderless <- geom_pointrange2


#' @rdname geom_point2
#' @export
geom_point_halo <- function(...) {
fun <- ggplot2::geom_point
.geom_halo(fun, ...)
}


#' @rdname geom_point2
#' @export
geom_jitter_borderless <- function(...) {
geom_jitter(pch = 21, color = .get_theme_bg_color(), ...)
geom_jitter_halo <- function(...) {
fun <- ggplot2::geom_jitter
.geom_halo(fun, ...)
}


#' @rdname geom_point2
#' @export
geom_pointrange_borderless <- function(...) {
geom_pointrange(pch = 21, color = .get_theme_bg_color(), ...)
geom_count_halo <- function(...) {
fun <- ggplot2::geom_count
.geom_halo(fun, ...)
}


.get_theme_bg_color <- function() {
current_theme <- ggplot2::theme_get()
#' @rdname geom_point2
#' @export
geom_pointrange_halo <- function(...) {
fun <- ggplot2::geom_pointrange
.geom_halo(fun, ...)
}


if (is.null(current_theme$panel.grid.major)) {
current_theme$panel.grid.major <- current_theme$panel.grid
.geom_halo <- function(fun, ...) {
dots <- list(...)
if (!is.null(dots$color)) {
dots$fill <- dots$color
}
if (!is.null(dots$colour)) {
dots$fill <- dots$colour
}

dots$colour <- dots$shape <- dots$pch <- NULL
dots$color <- .get_theme_bg_color()

fun_args <- c(list(pch = 21), dots)
do.call(fun, fun_args)
}


.get_theme_bg_color <- function() {
current_theme <- ggplot2::theme_get()

bg_color <- ifelse(
is.null(current_theme$panel.grid.major$colour),
is.null(current_theme$panel.background$fill),
"white",
current_theme$panel.grid.major$colour
current_theme$panel.background$fill
)

bg_color
Expand Down
45 changes: 33 additions & 12 deletions man/geom_point2.Rd

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

Loading
Loading