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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:14:54+00:00 2026-06-09T09:14:54+00:00

I have monthly data that I would like to draw the predicted values: z

  • 0

I have monthly data that I would like to draw the predicted values:

z <- structure(list(Date = structure(c(14610, 14641, 14669, 14700, 
14730, 14761, 14791, 14822, 14853, 14883, 14914, 14944, 14975, 
15006, 15034, 15065, 15095, 15126, 15156, 15187, 15218, 15248, 
15279, 15309, 15340, 15371, 15400, 15431, 15461), class = "Date"), 
    Value = c(4.5e+07, 5.1e+07, 5.6e+07, 5.6e+07, 5.9e+07, 6e+07, 
    6e+07, 6e+07, 6.4e+07, 6.5e+07, 7.5e+07, 7.3e+07, 7.4e+07, 
    8e+07, 8.7e+07, 9.1e+07, 9.2e+07, 9.6e+07, 1.09e+08, 1.08e+08, 
    1.23e+08, 1.29e+08, 1.33e+08, 1.43e+08, 1.27e+08, 1.27e+08, 
    1.23e+08, 1.21e+08, 1.3e+08)), .Names = c("Date", "Value"
), row.names = c(NA, -29L), class = "data.frame")

a <- seq(as.Date(tail(z, 1)$Date), by="month", length=5) 
a <- data.frame(Date = a) 
z.lm <- lm(Value ~ Date, data=x) 
z.pre<-predict(z.lm, newdata=a)

I can plot the z data as this:
This works:

 plot(z$Date, z$Value, type="l", col="blue", 
      xlim=(c(as.Date(head(x,1)$Date)), c(as.Date(tail(a,1)$Date)), xaxt="n"))

 axis(1, z$Date, format(z$Date, "%b %Y"), cex.axis = .7) 

when I try to plot the predicted values as this:

lines(z.pre, col="red")

I don’t get errors but I dont see the red lines graph added to original plot.

Any ideas?

  • 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-09T09:14:56+00:00Added an answer on June 9, 2026 at 9:14 am

    You need to specify the xlim and ylim arguments correctly. Each of these should be a numeric vector of length 2.

    The function range() is handy for this. Try:

    plot(x$Date, x$Value, type="l", col="blue", xaxt="n",
         xlim=range(c(a$Date, x$Date)),
         ylim=range(c(z.pre, x$Value))
    )
    
    axis(1, x$Date, format(x$Date, "%b %Y"), cex.axis = .7) 
    
    lines(a$Date, z.pre, col="red")
    

    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 have a select statement that gathers data from one monthly-summary table like the
I have a hypothetical set of data with 3 columns that has monthly profit
I have 100 years of monthly data where each month is a file and
I have a function that performs a monthly task on one or more specified
We have a number of customers that we have to send monthly invoices too.
!Modified! I have a table (mySQL 5.0.x) which contains values for date ranges. |
I have monthly data in one data.table and annual data in another data.table and
I have a data frame with an year of daily values of rainfall (complete
I have an existing business application written in Excel which the client would like
I have a cube with a typical snapshot structure and daily granularity (like inventory

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.