joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 71 forks source link

Allow users to remove time range from plot title #247

Closed joshuaulrich closed 2 years ago

joshuaulrich commented 6 years ago

A plot of an xts object always contains the timespan to the right of the main title. There is currently no way to omit the range from the title. Several users have asked how to remove it, so there needs to be a way to accomplish that.

My first thought is that we omit the timespan if the user provides a value for main. But what if they want a custom title and the timespan?

Maybe we add a main.range argument? It could be TRUE by default, and the user could set it to FALSE and/or a format (e.g. "%Y-%m-%d")?

joshuaulrich commented 6 years ago

This answer on StackOverflow shows how to always remove the date range. Here's the relevant code from the answer:

plotxts <- fix("plot.xts")
# In the editor that opens, replace the lines below:
###    text.exp <- c(expression(text(xlim[1], 0.5, main, font = 2, 
###        col = theme$labels, offset = 0, cex = 1.1, pos = 4)), 
###        expression(text(xlim[2], 0.5, paste(start(xdata[xsubset]), 
###            end(xdata[xsubset]), sep = " / "), col = theme$labels, 
###            adj = c(0, 0), pos = 2)))
###    cs$add(text.exp, env = cs$Env, expr = TRUE)
# with these lines:
###    text.exp <- expression(text(xlim[1], 0.5, main, font = 2,
###        col = theme$labels, offset = 0, cex = 1.1, pos = 4))

# Finally, you need to ensure your copy's environment is the xts namespace:
environment(plotxts) <- asNamespace("xts")