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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:17:16+00:00 2026-06-07T17:17:16+00:00

I am creating a times series using ggplot2 in R. I would like to

  • 0

I am creating a times series using ggplot2 in R. I would like to know how to show tick marks in the x-axis only for the months that are labeled (e.g. Mar 07, Mar 08, etc) while keeping the vertical grey lines for every single month.

The main reason is because having a tick mark for every month makes it hard to know which one correspond to the labels.

Here is an example of a plot:

See how ticks on the x-axis make it hard to know where is each month

Here is the line of R behind:

ggplot(timeseries_plot_data_mean,aes(as.numeric(project_date)))+
   geom_line(aes(y=num_views))+geom_point(aes(y=num_views))+
   stat_smooth(aes(y=num_views),method="lm")+
   scale_x_continuous(breaks = xscale$breaks, labels = xscale$labels)+
   opts(title="Monthly average num views")+xlab("months")+ylab("num views")

This is what would like to generate. See how the ticks are positioned right above the month label and the vertical lines are still there showing each month.

This is what would like to generate (Inkscape, image editor,strangely replaced the dots for q's

I manually edited the plot above using Inkscape, (ignore the q’s, Inkscape strangely replaced the dots for q’s)

  • 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-07T17:17:19+00:00Added an answer on June 7, 2026 at 5:17 pm

    Here is a solution using the minor_breaks parameter of scale_x_date(). To use this, your x-values must be of class Date instead of numeric.

    library(ggplot2)
    set.seed(123)
    
    x <- seq(as.Date("2007/3/1"), as.Date("2012/4/1"), by = "1 month")
    y <- ((exp(-10 * seq(from=0, to=1, length.out=length(x))) * 120) +
          runif(length(x), min=-10, max=10))
    
    dat <- data.frame(Months=x, Views=y)
    
    x_breaks <- seq(as.Date("2007/3/1"), as.Date("2012/4/1"), by="1 year")
    x_labels <- as.character(x_breaks, format="%h-%y")
    
    plot_1 <- ggplot(dat, aes(x=Months, y=Views)) +
              theme_bw() +
              geom_line() +
              geom_point() +
              scale_x_date(breaks=x_breaks, labels=x_labels, minor_breaks=dat$Months)
    
    png("plot_1.png", width=600, height=240)
    print(plot_1)
    dev.off()
    

    plot_1.png

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

Sidebar

Related Questions

in django I am creating data series using datetime.date() objects, like this: data.append([ddate, daily_score])
I am creating a program that displays a popup at certain times (just like
I'm creating a time-series object with new variables using the transform() function in R
I am currently trying to show a series of images that slightly differ from
I am creating a chart control chart1.ChartAreas.Add(area); chart1.series.add(time); //loop //get values of a and
I'm used to creating the UI, BLL, DAL by hand (some times I've used
I was creating a countdown timer using javascript; I can use jQuery. I want
How would you guys go about creating a real-time search engine on .Net platform.
Creating a simple RPG game, first time using XNA. Trying to get my character
I am busy creating a less complicated version of NinePatchDrawable that tiles the inner

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.