Skip to content

Commit 0e3095f

Browse files
Issue #359 for jitter layer (#560)
* fixes #559 * add test * news
1 parent 29bfe67 commit 0e3095f

4 files changed

Lines changed: 225 additions & 1 deletion

File tree

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ where the formatting is also better._
2525

2626
- Jittered plots now support Date/POSIXt axes. Thanks to @wachtermh for the bug
2727
report and @vincentarelbundock for the code contribution. (#327)
28+
- `tinyplot_add(type = "jitter")` no longer errors when layered on top of
29+
boxplot, violin, or similar categorical plot types. (#560 @grantmcdermott)
2830

2931
### Internals
3032

R/align_layer.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ align_layer = function(settings) {
3434
} else if (!is.null(names(xlabs_layer))) {
3535
# Case 2: match implicit integer -> label mapping (e.g., lines added to errorbars)
3636
if (setequal(names(xlabs_layer), names(xlabs_orig))) {
37+
# If mappings already agree and no dodge, no realignment needed
38+
if (identical(xlabs_layer, xlabs_orig) && is.null(settings$dodge)) return(invisible())
3739
orig_order = xlabs_orig[names(xlabs_layer)[settings$datapoints[["x"]]]]
3840
x_layer = settings$datapoints[["x"]]
3941
if (is.null(settings$dodge)) {
@@ -55,4 +57,3 @@ align_layer = function(settings) {
5557
}
5658
}
5759
}
58-

inst/tinytest/_tinysnapshot/tinyplot_add_jitter_on_violin.svg

Lines changed: 212 additions & 0 deletions
Loading

inst/tinytest/test-tinyplot_add.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,12 @@ f = function() {
9393
tinyplot_add(type = "lm")
9494
}
9595
expect_snapshot_plot(f, label = "tinyplot_add_no_recursive_margins")
96+
97+
98+
# jitter layer on top of boxplot (#559)
99+
set.seed(42)
100+
f = function() {
101+
tinyplot(Sepal.Length ~ Species, data = iris, type = "violin")
102+
tinyplot_add(type = "jitter", cex = 0.5, alpha = 0.3)
103+
}
104+
expect_snapshot_plot(f, label = "tinyplot_add_jitter_on_violin")

0 commit comments

Comments
 (0)