Skip to content

sina plot - #734

Merged
grantmcdermott merged 7 commits into
mainfrom
sina-plot
Sep 16, 2026
Merged

grantmcdermott merged 7 commits into
mainfrom
sina-plot

Conversation

@grantmcdermott

@grantmcdermott grantmcdermott commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Closes #359

(At least, I feel that this is a fair substitute for the original beeswarm request.)

MWE

pkgload::load_all("~/Documents/Projects/tinyplot")
#> ℹ Loading tinyplot

plt(bill_len ~ species, data = penguins, type = "sina")

plt(bill_len ~ species | species, data = penguins, type = "violin", alpha = 0.5,
    theme = "clean")
plt_add(type = "sina", alpha = 0.3)

Created on 2026-09-15 with reprex v2.1.1

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved sina/violin edge-case issues and missing regression coverage remain before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds a density-based sina plot type as a beeswarm alternative, with shared violin preparation and supporting documentation.

Changes:

  • Implements deterministic/random sina point spreading and singleton handling.
  • Refactors shared violin/sina density preparation.
  • Propagates bandwidth adjustment support.
  • Adds registration, tests, snapshots, documentation, and navigation updates.
File summaries
File Reviewed change
vignettes/types.qmd Adds sina to the type guide.
R/zzz.R Registers plotting globals.
R/type_violin.R Refactors shared distribution preparation.
R/type_sina.R Implements sina plotting and spread methods.
R/type_ridge.R Passes bandwidth adjustment to density estimation.
R/type_density.R Passes bandwidth adjustment to density estimation.
R/sanitize_type.R Registers the sina type.
NEWS.md Announces the new plot type.
NAMESPACE Updates exports and imports.
man/type_violin.Rd Documents violin and sina behavior.
inst/tinytest/test-type_sina.R Adds sina tests and snapshots.
inst/tinytest/_tinysnapshot/sina_singletons_keep.svg Singleton snapshot.
inst/tinytest/_tinysnapshot/sina_on_violin.svg Layering snapshot.
inst/tinytest/_tinysnapshot/sina_groups.svg Grouped sina snapshot.
inst/tinytest/_tinysnapshot/sina_by_continuous.svg Continuous-group snapshot.
altdoc/quarto_website.yml Adds sina to website navigation.
Review details

Files not reviewed (1)

  • man/type_violin.Rd: Generated file

Suppressed comments (5)

R/type_density.R:214

  • This now passes the user-supplied adjust value through to density(), but the density tests only exercise the default adjust = 1, so they would pass even if this regression were reintroduced. Add a focused non-default adjust test or snapshot that distinguishes the bandwidth from the default.
            density(dat$x, bw = dens_bw, adjust = adjust, kernel = kernel, n = n, weights = wts)

R/type_ridge.R:362

  • This fixes type_ridge() to honor non-default adjust, but the ridge tests do not exercise that argument, so the old behavior would remain undetected. Add a focused non-default adjust test or snapshot before relying on this fix.
      dens = density(dat$x, bw = dens_bw, adjust = adjust, kernel = kernel, n = n)

R/type_sina.R:125

  • If every cell is a singleton and the user selects the documented "warn" or "drop" policy, cells is empty and do.call(rbind, datapoints) returns NULL. The later limit calculation then takes ranges from empty vectors and errors instead of producing a plot with the singleton observations removed. Handle the zero-cell result with a valid empty data frame and consistent axis/facet/group state.
        datapoints = do.call(rbind, datapoints)

R/type_violin.R:364

  • The singleton check only looks at row count, so a cell with two or more identical y values still reaches the data-driven bandwidth calculation and density(). With the default bw = "nrd0", base R cannot estimate a bandwidth for an essentially constant sample, so valid repeated observations can make the sina plot error instead of drawing them. Handle zero-variance cells like singleton cells or provide a safe fallback bandwidth.
        bws = sapply(smoothable, function(dat) bw_fun(kernel = bw, dat[["y"]]))

R/type_violin.R:193

  • This changes violin geometry for non-default adjust, but the violin tests only use the default value, so they cannot distinguish this implementation from the pre-change code. Add a focused non-default adjust test or snapshot to protect the documented argument.
                dens = density(dat$y, bw = dens_bw, adjust = adjust, kernel = kernel, n = n, from = yrng[1], to = yrng[2])
  • Files reviewed: 11/16 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread R/type_violin.R
Comment thread R/type_sina.R Outdated
Comment thread R/type_violin.R
Comment thread R/type_violin.R
@grantmcdermott
grantmcdermott merged commit aff03fd into main Sep 16, 2026
3 checks passed
@grantmcdermott
grantmcdermott deleted the sina-plot branch September 16, 2026 03:57
@grantmcdermott grantmcdermott mentioned this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bee swarm plot

2 participants