tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
531 stars 49 forks source link

plot.tbl_ts method? #202

Closed mpadge closed 4 years ago

mpadge commented 4 years ago

Please feel free to judge this as out-of-scope. It's just a thought raised by @rkillick, and which would personally make sense to me.

What i would like

Default plot on tsibble objects to put the index axis on the horizontal (unless otherwise specified or controlled).

Current behaviour

library (tsibble)
n <- 10
vals <- 1:n
x <- tsibble (y = runif (n),
              time = vals,
              index = time)
plot (x, type = "l")

The index variable is automatically put on 2nd (y) axis, because it's the 2nd column.

A solution

(This is nothing like what implemented code should look like, but illustrates the point.)

plot.tbl_ts <- function (x, ...) {
    i <- match (index_var (x), names (x))
    o <- c (i, seq (ncol (x)) [-i])
    plot.default (x [, o], ...)
}

plot (x, type = "l")

Created on 2020-06-25 by the reprex package (v0.3.0)

There is current no default plot.tbl_ts method, for likely very good and understandable reasons. Foremost among these is unintended side effects, which this makes no attempt to anticipate. Nevertheless might be worth thinking about?

rkillick commented 4 years ago

Users of ts objects would be expecting time on the x-axis as this is the default plot.ts. As Mark states, there may be a reason for not having a separate plot.tbl_ts method, but if not then the anticipated behaviour would be time on the x-axis.

earowang commented 4 years ago

All graphical methods for tsibble are available in the {feasts} package. We provide autoplot() for time series plots using ggplot, instead of plot().