Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8182701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:56:20+00:00 2026-06-07T00:56:20+00:00

I was wondering how I could plot more tick marks when plotting time on

  • 0

I was wondering how I could plot more tick marks when plotting time on the x-axis.

Basically, a time equivalent to pretty. Pretty obviously doesn’t work so well with times, as it uses factors of 1,2,5 and 10. For time one probably wants e.g. hours, half hours, …

plot(as.POSIXct(x,origin="1960-01-01"),y,type="l",xlab="Time")

gives really too few and widely spaced tickmarks.

zoox<-zoo(y,as.POSIXct(stats$Time,origin="1960-01-01"))
plot(zoox)

gives the same.

Thanks

EDIT:

Just to clarify (so far answers don’t address my issue): What I am looking for is a function like pretty for dates, e.g. a function, that takes a start date, an end date, a number of ticks, and outputs the location of the ticks. That is, I am well aware it is possible to plot hours, to plot minutes, and what else, but pretty automates the tick distance for numbers, and a resulting function for dates should decide by itself whether to use days, hours, minutes, second, milliseconds, microseconds, 30 minutes, 500 micros, 5 seconds, etc. intervals. That is what pretty does for numbers, anyway.

EDIT2:

This is the function I currently use to decide the format for the time axis (note that this doesn’t work for dates):

mydiff <- end-start
if(mydiff>1800) {
    axis.POSIXct(1,xrange,format="%H:%M")
} else if(mydiff>30) {
    axis.POSIXct(1,xrange,format="%H:%M:%S")
} else if(mydiff>0.5) {
    axis.POSIXct(1,xrange,format="%H:%M:%OS3")
} else
    axis.POSIXct(1,xrange,format="%H:%M:%OS6")
}

I don’t have a function that increase tick marks, so I use the default number of tick marks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:56:22+00:00Added an answer on June 7, 2026 at 12:56 am

    axis.POSIXct() already works quite hard to guess suitable pretty values for the axis, so I would start by hacking that. At the moment, it relies internally on using pretty() applied to the some function of the datetimes. It uses the defaults for pretty() so you could hack the function to add an n or min.n argument which would increase the number of pretty marks selected.

    Copy axis.POSIXct() to your own function/file (give it a new name). Add a n or min.n argument to the definition, probably with larger values as defaults than those used by the pretty() function. And pass that to each of the pretty() calls that is made.

    Try it out. If it works reasonably well, then you can do fixInNamespace(axis.POSIXct) to make the same changes to the actual function so it gets used on all plots for which it is called.

    P.S. Here is a possible hack

    function (side, x, at, format, labels = TRUE, n = 5, ...) {
      mat <- missing(at) || is.null(at)
      if (!mat) 
        x <- as.POSIXct(at)
      else x <- as.POSIXct(x)
      range <- par("usr")[if (side%%2) 
        1L:2L
        else 3L:4L]
      d <- range[2L] - range[1L]
      z <- c(range, x[is.finite(x)])
      attr(z, "tzone") <- attr(x, "tzone")
      if (d < 1.1 ) {
        sc <- 0.001
        if (missing(format)) 
          format <- "%H:%M:%OS6"
      }
      else if (d < 1.1 * 30) {
        sc <- 1
        if (missing(format)) 
          format <- "%H:%M:%OS3"
      }
      else if (d < 1.1 * 60) {
        sc <- 1
        if (missing(format)) 
          format <- "%H:%M:%S"
      }
      else if (d < 1.1 * 30 * 60) {
        sc <- 60
        if (missing(format)) 
          format <- "%H:%M:%S"
      }
      else if (d < 1.1 * 60 * 60) {
        sc <- 60
        if (missing(format)) 
          format <- "%H:%M"
      }
      else if (d < 1.3 * 60 * 60 * 24) {
        sc <- 60 * 60
        if (missing(format)) 
          format <- "%H:%M"
      }
      else if (d < 2 * 60 * 60 * 24) {
        sc <- 60 * 60
        if (missing(format)) 
          format <- "%a %H:%M"
      }
      else if (d < 7 * 60 * 60 * 24) {
        sc <- 60 * 60 * 24
        if (missing(format)) 
          format <- "%a"
      }
      else {
        sc <- 60 * 60 * 24
      }
      if (d < 60 * 60 * 24 * 50) {
        zz <- pretty(z/sc,n=n)
        z <- zz * sc
        z <- .POSIXct(z, attr(x, "tzone"))
        if (sc == 60 * 60 * 24) 
          z <- as.POSIXct(round(z, "days"))
        if (missing(format)) 
          format <- "%b %d"
      }
      else if (d < 1.1 * 60 * 60 * 24 * 365) {
        z <- .POSIXct(z, attr(x, "tzone"))
        zz <- as.POSIXlt(z)
        zz$mday <- zz$wday <- zz$yday <- 1
        zz$isdst <- -1
        zz$hour <- zz$min <- zz$sec <- 0
        zz$mon <- pretty(zz$mon,n=n)
        m <- length(zz$mon)
        M <- 2 * m
        m <- rep.int(zz$year[1L], m)
        zz$year <- c(m, m + 1)
        zz <- lapply(zz, function(x) rep(x, length.out = M))
        zz <- .POSIXlt(zz, attr(x, "tzone"))
        z <- as.POSIXct(zz)
        if (missing(format)) 
          format <- "%b"
      }
      else {
        z <- .POSIXct(z, attr(x, "tzone"))
        zz <- as.POSIXlt(z)
        zz$mday <- zz$wday <- zz$yday <- 1
        zz$isdst <- -1
        zz$mon <- zz$hour <- zz$min <- zz$sec <- 0
        zz$year <- pretty(zz$year,n=n)
        M <- length(zz$year)
        zz <- lapply(zz, function(x) rep(x, length.out = M))
        z <- as.POSIXct(.POSIXlt(zz))
        if (missing(format)) 
          format <- "%Y"
      }
      if (!mat) 
        z <- x[is.finite(x)]
      keep <- z >= range[1L] & z <= range[2L]
      z <- z[keep]
      if (!is.logical(labels)) 
        labels <- labels[keep]
      else if (identical(labels, TRUE)) 
        labels <- format(z, format = format)
      else if (identical(labels, FALSE)) 
        labels <- rep("", length(z))
      axis(side, at = z, labels = labels, ...)
    }
    

    Differences to the original function can be seen here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just wondering could ipod app use more cpu than the 600mhz (3rd
I was wondering if anyone could help me plot lines in R with multiple
I was wondering how could I use a custom object in more than one
gcc 4.6.2 c89 I am just wondering what could cause more memory issues. For
i am wondering could i access my app internal storage using emulator. I mean
Hi sorry still learning here and slow to learning code arguments. Just wondering could
i was wondering how could i emulate a mouse click with c# with kinect.
I'm wondering what could be some consequences of reusing the names of built-in types
I was wondering which could be a better way of mounting different apps for
I was wondering what could be the point in trying to delete committed changelists,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.