Skip to content

New stat: stat_connect() #6329

New issue

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

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

Already on GitHub? # to your account

Merged
merged 8 commits into from
Mar 25, 2025
Merged

New stat: stat_connect() #6329

merged 8 commits into from
Mar 25, 2025

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6228 and replaces #6231.

It follows the advice in #6231 (comment), where instead of implementing the idea as a position adjustment, it is implemented as a stat. Together with #6326, this should offer greater flexibility than a position adjustment.

The example section rendered:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

ggplot(head(economics, 20), aes(date, unemploy)) +
  stat_connect(connection = "hv")

# Setup custom connections
x <- seq(0, 1, length.out = 20)[-1]
smooth <- cbind(x, scales::rescale(1 / (1 + exp(-(x * 10 - 5)))))
zigzag <- cbind(c(0.4, 0.6, 1), c(0.75, 0.25, 1))

ggplot(head(economics, 10), aes(date, unemploy)) +
  geom_point() +
  stat_connect(aes(colour = "zigzag"), connection = zigzag) +
  stat_connect(aes(colour = "smooth"), connection = smooth)

Created on 2025-02-12 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM

@teunbrand teunbrand merged commit 63b263b into tidyverse:main Mar 25, 2025
12 of 13 checks passed
@teunbrand teunbrand deleted the stat_connect branch March 25, 2025 13:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: position_step()
2 participants