Skip to content
Open
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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ where the formatting is also better._
- The legend plot characters for the `"pointrange"` and `"errorbar"` types now
include a line, to better resemble the actual plot elements (#533 @grantmcdermott)

### Bug fixes

- Jittered plots now support Date/POSIXt axes. Thanks to @wachtermh for the bug
report and @vincentarelbundock for the code contribution. (#327)

### Internals

- We now encourage type-specific legend customizations within the individual
Expand Down
19 changes: 17 additions & 2 deletions R/type_jitter.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ type_jitter = function(factor = 1, amount = NULL) {
}


jitter_restore = function(obj, factor, amount) {
if (inherits(obj, "POSIXlt")) {
obj = as.POSIXct(obj)
}
if (inherits(obj, c("Date", "POSIXt", "yearmon", "yearqtr"))) {
obj_attrs = attributes(obj)
out = jitter(unclass(obj), factor = factor, amount = amount)
attributes(out) = obj_attrs
} else {
out = jitter(obj, factor = factor, amount = amount)
}
return(out)
}


data_jitter = function(factor, amount) {
fun = function(settings, ...) {
env2env(settings, environment(), "datapoints")
Expand All @@ -45,8 +60,8 @@ data_jitter = function(factor, amount) {
} else {
ylabs = NULL
}
x = jitter(x, factor = factor, amount = amount)
y = jitter(y, factor = factor, amount = amount)
x = jitter_restore(x, factor = factor, amount = amount)
y = jitter_restore(y, factor = factor, amount = amount)

datapoints$x = x
datapoints$y = y
Expand Down
Loading