Skip to content
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

Axis Date/POSIXct #272

Closed
ldecicco-USGS opened this issue Oct 13, 2015 · 2 comments
Closed

Axis Date/POSIXct #272

ldecicco-USGS opened this issue Oct 13, 2015 · 2 comments
Assignees
Labels
Milestone

Comments

@ldecicco-USGS
Copy link
Member

If the user wanted to call axis.Date or axis.POSIXct...they'd have problems:

gs <- gsplot() %>%
      points(x=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 20),
             y=1:20,axes=FALSE) %>%
      axis(1, at=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 5))
gs
@jordansread
Copy link
Member

in base, this would require you to do:

plot(x=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 20),
             y=1:20,axes=FALSE, ylab=NA,xlab=NA)
axis.Date(1, at=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 5))
box()

because axis(1, at=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 5)) does the same thing as gsplot's axis

options:

  1. gsplot has an override function for axis.Date and axis.POSIXct:
gs <- gsplot() %>%
      points(x=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 20),
             y=1:20,axes=FALSE) %>%
      axis.Date(1, at=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 5))
gs
  1. gsplot tries to be smart w/ axis based on the class of the incoming data. This is tricky because the Date and POSIX axis sneak in an x param:
names(formals(graphics::axis))
 [1] "side"      "at"        "labels"    "tick"      "line"      "pos"       "outer"     "font"      "lty"       "lwd"       "lwd.ticks" "col"       "col.ticks" "hadj"      "padj"      "..."      
names(formals(graphics::axis.Date))
[1] "side"   "x"      "at"     "format" "labels" "..." 

probably doable though.

I think the way it works right now might not be a bug, since it mimics the way base would do it.

But, it does bring up the issue of trying to use a function that gsplot doesn't have an override for:

gs <- gsplot() %>%
      points(x=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 20),
             y=1:20,axes=FALSE) %>%
      axis.Date(1, at=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),length.out = 5))
Error in side%%2 : non-numeric argument to binary operator

which is not a very helpful error

@lindsayplatt lindsayplatt modified the milestone: 0.8.0 Oct 24, 2016
@lindsayplatt lindsayplatt self-assigned this Oct 24, 2016
@lindsayplatt
Copy link

@ldecicco-USGS @jread-usgs not sure what the original issue with this was, but with what is currently on the master branch, I get:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants