diff --git a/NEWS.md b/NEWS.md index 2b6bf2b0..853c89bc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -40,10 +40,10 @@ where the formatting is also better._ axis limits for secondary plot layers. (#513 @grantmcdermott) - Fixed lazy evaluation bug where `legend` passed as a symbol through S3 methods (e.g., `tinyplot.foo`) would fail. (#515 @grantmcdermott) -- Added layers, particularly from `tinyplot_add()`, should now respect the x-axis - order of the original plot layer. This should ensure that we don't end up with - misaligned layers. For example, when adding a ribbon on top of an errorbar - plot. (#517 @grantmcdermott) +- Added layers, particularly from `tinyplot_add()`, should now respect the + x-axis order of the original plot layer. This should ensure that we don't end + up with misaligned layers. For example, when adding a ribbon on top of an + errorbar plot. (#517, #520 @grantmcdermott) ### Documentation diff --git a/R/tinyplot.R b/R/tinyplot.R index 6c764633..b186ddf9 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -1217,6 +1217,7 @@ tinyplot.default = function( datapoints[[dp_var]] } ) + datapoints = datapoints[order(datapoints[[dp_var]]), ] } else if (!is.null(names(labs_layer))) { # case 2: match implicit integer -> label mapping (e.g., lines added to errorbars) if (setequal(names(labs_layer), names(labs_orig))) { diff --git a/inst/tinytest/_tinysnapshot/pointrange_with_layers_grouped.svg b/inst/tinytest/_tinysnapshot/pointrange_with_layers_grouped.svg new file mode 100644 index 00000000..0b41a534 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/pointrange_with_layers_grouped.svg @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + +model +Model A +Model B +Model C + + + + + + + +term +estimate + + + + + + + +(Intercept) +wt +cyl +hp + + + + + + +0 +10 +20 +30 +40 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/test-type_pointrange.R b/inst/tinytest/test-type_pointrange.R index 06d8dd80..d2f14477 100644 --- a/inst/tinytest/test-type_pointrange.R +++ b/inst/tinytest/test-type_pointrange.R @@ -94,3 +94,15 @@ fun = function() { type = type_pointrange(dodge = 0.2)) } expect_snapshot_plot(fun, label = "pointrange_dodge_01") + +# issue #519 layer on top of grouped plots +# (don't care about dodge yet; revist when #493 resolved) + +fun = function() { + tinyplot(estimate ~ term | model, + ymin = conf.low, ymax = conf.high, + data = results, + type = type_pointrange()) + tinyplot_add(type = 'l') +} +expect_snapshot_plot(fun, label = "pointrange_with_layers_grouped") \ No newline at end of file