Skip to content

tinyplot method for 'ts' time series objects#558

Open
zeileis wants to merge 5 commits intomainfrom
ts-method
Open

tinyplot method for 'ts' time series objects#558
zeileis wants to merge 5 commits intomainfrom
ts-method

Conversation

@zeileis
Copy link
Collaborator

@zeileis zeileis commented Mar 22, 2026

In order to visualize ts time series with tinyplot it would be nice to have a dedicated method. Internally, this would just set up a long data frame, e.g., with variables Time, Value, and Series and then call tinyplot() with a suitable formula.

As you know, I previously already created a similar method in our zoo package, see: https://github.com/cran/zoo/blob/master/R/tinyplot.zoo.R. And for my personal usage it was enough to do tinyplot(as.zoo(x)) if x is a ts series. However, currently I'm teaching my time series course where I still work with quite a few ts series as well and felt it would be nice to have a native ts method.

Hence, this PR suggests such a method. I will need a few more commits to set up tests and news, etc. I will also post some examples in this PR...hopefully later today.

@zeileis
Copy link
Collaborator Author

zeileis commented Mar 22, 2026

Examples from the manual page using tinytheme("clean2"):

## univariate series
tinyplot(Nile)
ts1
## multivariate 
tinyplot(EuStockMarkets) ## multiple, same color, free scales
ts2
tinyplot(EuStockMarkets, facet.args = NULL) ## multiple, same color, same scale
ts3
tinyplot(EuStockMarkets, facet = "by") ## multiple, separate colors, free scales
ts4
tinyplot(EuStockMarkets, facet = NULL) ## single, separate colors
ts5
tinyplot(EuStockMarkets, facet = "by", facet.args = NULL)
ts6
tinyplot(EuStockMarkets, facet.args = list(free = TRUE, ncol = 1))
ts7

@zeileis
Copy link
Collaborator Author

zeileis commented Mar 22, 2026

Caveats:

  1. The default plot layout for multivariate time series is a bit different than in the base plot().

    plot(EuStockMarkets)
    
    ts0

    It wouldn't be hard to replicate the behavior but I don't think that it is worth it and it is better to be consistent with standard tinyplot behavior. Instead we could think about ways to facilitate layout with everything in one column (or one row), e.g., by supporting facet = Series ~ 1 and facet = 1 ~ Series. But I'll leave this for another PR.

  2. Currently, only facet is an argument to tinyplot.ts, maybe by should be exported as well?

  3. The method always assumes that the formula to apply is Value ~ Time or Value ~ Time | Series. Thus, it is not possible to have ~ Value as would be needed for a histogram. This is the reason why currently two test cases break. The simpler one is tinyplot(Nile, type = "histogram"). I'm not sure what is the best way forward here: Dispatching to tinyplot.default for selected type specifications? Changing the test case? Exporting the formula argumentas well and setting different defaults for differenttype` specifications?

I'll stop here for now and wait for your feedback. It's _not_ urgent! I just wanted to write these things down while they are fresh in my mind.

@grantmcdermott
Copy link
Owner

Thanks. @zeileis, this is very cool. I'm still in the middle of busy path, but had some FOSS time tonight so had a peek and can give you my quick thoughts:

  1. Agree that we stay with idiomatic tinyplot defaults. I'd encourage single column facets via the standard facet.args(ncol = 1) argument now... Although I like your idea of facet = Series ~ 1. My feeling is that this requires a separate PR, though.
  2. Yes, ideally we'd allow by too. In fact, again thinking about expected tinyplot behaviour, my sense is that we should group by default instead of diverting to facets. I realise that this is a break with plot, but I'd prefer for us to maintain internal consistency if we had to break with one or the other. (Maybe the default is tinyplot.ts(..., facet = "by")?)
  3. I haven't tested locally, so I haven't seen the other failure. But I'd very much like to preserve tinyplot(Nile, type = "histogram") behaviour. I haven't thought this through carefully, but could we maybe skip the internal Value ~ Time (| Series) formula validation if the user provides an explicit (non-NULL) type?

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.

2 participants