New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot.xts axis only shows two labels #246

Closed
eddelbuettel opened this Issue Jun 11, 2018 · 8 comments

Comments

Projects
None yet
3 participants
@eddelbuettel
Contributor

eddelbuettel commented Jun 11, 2018

Description

The x-axis annotation is somewhat overly sparse on irregular data

Expected behavior

I would expect the usual four to five ticks to be shown

Minimal, reproducible example

The image comes from running the example which requires the package. The same effect appears
just with the code not commented out here

## library(RcppUTS)
## example(EMAnext)
##
## or directly:
suppressMessages(library(xts))
times <- ISOdatetime(2010, 1, 2, 8, 30, 0) + c(0, 1.0, 1.2, 2.3, 2.9, 5.0)
values <- seq(0, 10, by=2)
plot(xts(values, order.by=times), type="b",
         main="Series and last/next/linear EMAs")
#lines(xts(EMAlast(times,values, 1),  values, order.by=times),
#          type="b", col="lightblue")
#    lines(xts(EMAnext(times,values, 1),  values, order.by=times),
#          type="b", col="darkblue")
#   lines(xts(EMAlinear(times,values, 1),  values, order.by=times),
#          type="b", col="mediumblue")
    addLegend("topleft", legend.names=c("series", "EMAlast", "EMAnext", "EMAlinear"),
              lty=rep(1,4), lwd=rep(1,4),
              col=c("black", "lightblue", "darkblue", "mediumblue"))

will re-create the same plot shown on the repository README.md and here:

image

Session Info

Current CRAN versions of everything.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Jun 11, 2018

Contributor

BTW I tried to research this in old issue tickets and did not see it posted. My bad if I missed one.

/cc @rossb34

Contributor

eddelbuettel commented Jun 11, 2018

BTW I tried to research this in old issue tickets and did not see it posted. My bad if I missed one.

/cc @rossb34

@joshuaulrich

This comment has been minimized.

Show comment
Hide comment
@joshuaulrich

joshuaulrich Jun 11, 2018

Owner

Thanks for the report. This has bothered me too, but never enough to take a look. Seems like the solution could be as simple as setting major.ticks = "auto" and grid.ticks.on = "auto" as the plot.xts() defaults. It works for your example.

Owner

joshuaulrich commented Jun 11, 2018

Thanks for the report. This has bothered me too, but never enough to take a look. Seems like the solution could be as simple as setting major.ticks = "auto" and grid.ticks.on = "auto" as the plot.xts() defaults. It works for your example.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Jun 11, 2018

Contributor

That helps indeed. The documentation on those options and these values is a bit ... sparse.

Contributor

eddelbuettel commented Jun 11, 2018

That helps indeed. The documentation on those options and these values is a bit ... sparse.

@rossb34

This comment has been minimized.

Show comment
Hide comment
@rossb34

rossb34 Jun 11, 2018

Collaborator

I agree with @joshuaulrich that setting the default arguments to "auto" for the grid and axis ticks is a good solution. The default is "months" which is only reasonable for several months of data on a daily or lower frequency.

plot.xts uses xts:::axTicksByTime2 which is a port from what is used in quantmod::chart_Series, also mentioned in #74.

Collaborator

rossb34 commented Jun 11, 2018

I agree with @joshuaulrich that setting the default arguments to "auto" for the grid and axis ticks is a good solution. The default is "months" which is only reasonable for several months of data on a daily or lower frequency.

plot.xts uses xts:::axTicksByTime2 which is a port from what is used in quantmod::chart_Series, also mentioned in #74.

@rossb34

This comment has been minimized.

Show comment
Hide comment
@rossb34

rossb34 Jun 11, 2018

Collaborator

@eddelbuettel thanks for the note on documentation. I'll add language to improve the documentation.

Collaborator

rossb34 commented Jun 11, 2018

@eddelbuettel thanks for the note on documentation. I'll add language to improve the documentation.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Jun 11, 2018

Contributor

I am also looking at what rtsplot::rtsplot() does -- and it is pretty compelling. Just extended some intra-daily data from one to several days and it put weekdays on the axis.

Contributor

eddelbuettel commented Jun 11, 2018

I am also looking at what rtsplot::rtsplot() does -- and it is pretty compelling. Just extended some intra-daily data from one to several days and it put weekdays on the axis.

@joshuaulrich

This comment has been minimized.

Show comment
Hide comment
@joshuaulrich

joshuaulrich Jun 12, 2018

Owner

rtsplot::rtsplot() uses graphics::axis.POSIXct(), which plot.xts() cannot use because of its different geometry. That said, we may be able to use a similar approach.

One possible problem: xts objects are often irregularly spaced, which means there could easily be no observations where you would want to place a tick mark based on the logic in graphics::axis.POSIXct(). This is why axTicksByTime() uses endpoints() to find tick mark locations.

Owner

joshuaulrich commented Jun 12, 2018

rtsplot::rtsplot() uses graphics::axis.POSIXct(), which plot.xts() cannot use because of its different geometry. That said, we may be able to use a similar approach.

One possible problem: xts objects are often irregularly spaced, which means there could easily be no observations where you would want to place a tick mark based on the logic in graphics::axis.POSIXct(). This is why axTicksByTime() uses endpoints() to find tick mark locations.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Jun 12, 2018

Contributor

Casual usage of both over the last couple of days with generally irregular data has rtsplot() as a winner.

I am sure there are counter-examples. I have not yet hit any. I'll follow up if I do.

Contributor

eddelbuettel commented Jun 12, 2018

Casual usage of both over the last couple of days with generally irregular data has rtsplot() as a winner.

I am sure there are counter-examples. I have not yet hit any. I'll follow up if I do.

@joshuaulrich joshuaulrich added this to the Release 0.11-0 milestone Jul 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment