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 6938339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:28:51+00:00 2026-05-27T12:28:51+00:00

i am displaying time series data with ggplot2 but the tick-labels show some strange

  • 0

i am displaying time series data with ggplot2 but the tick-labels show some strange behaviour. probably i am doing something wrong but i could not find any help on the internet. here’s an example:

#just sample data
time <- as.Date(seq(as.Date("2004/1/1"), as.Date("2009/12/1"), by = "1 month"))
data <- rnorm(nrow(test))+c(1:nrow(test))
test <- data.frame(time, data)

i plot with:

q1 <- ggplot(data=test) + geom_line(aes(x=time, y=data))
q1 <- q1 + scale_x_date(major="years", minor="3 months", format="%Y-%m", lim=c(as.Date("2004/1/1"),as.Date("2009/12/1")), name="") 
q1

this produces the following graph:
example graph

but from my understanding the grid should end 2009/12/1 – right? thanks a lot for your help!

  • 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-05-27T12:28:51+00:00Added an answer on May 27, 2026 at 12:28 pm

    The limits parameter to scale_x_date affects which data points are plotted, but does not directly change the axis tick labels nor the axis range. This behavior is well illustrated in the help page http://had.co.nz/ggplot2/scale_date.html (towards the bottom of the page.)

    If you want to eliminate the empty areas to left and right of your data, use coord_cartesian

    library(ggplot2)
    
    x <- as.Date(seq(as.Date("2004/1/1"), as.Date("2009/12/1"), by = "1 month"))
    y <- rnorm(length(x))+c(1:length(x))
    test <- data.frame(time=x, data=y)
    
    q2 <- ggplot(data=test) + 
          geom_line(aes(x=time, y=data)) +
          scale_x_date(major="years", minor="3 months", format="%Y-%m", name="") +
          coord_cartesian(xlim=c(as.Date("2004/1/1"),as.Date("2009/12/1")))
    
    png("date_ticks_plot.png", height=600, width=600)
    print(q2)
    dev.off()
    

    enter image description here

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

Sidebar

Related Questions

I'm having some trouble displaying the time in this format: HH:mm:ss. No matter what
I'm writing a windows application which is displaying real time data on a map.
I am displaying several time series lines along with Markers on a JFreeChart plot.
I have some table cells displaying different time. I want the time to be
My application needs to display the time. Rather then displaying time as 11:00 I
How to create simple PHP COMET server page displaying current time? I need code
I am displaying a scrolled data table in a web page. This table has
I need a slider for displaying real time in slider-label from 12-00 AM to
I have a series of yes/no questions that I am displaying one at a
i am displaying time in the label which is inside the grid view. i

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.