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

  • Home
  • SEARCH
  • 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 9082679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:36:57+00:00 2026-06-16T20:36:57+00:00

dput(df) structure(list(Month = structure(c(15248, 15522), class = Date), Value = c(1, 3)), .Names =

  • 0
dput(df)
structure(list(Month = structure(c(15248, 15522), class = "Date"), 
    Value = c(1, 3)), .Names = c("Month", "Value"), row.names = 1:2, class = "data.frame")

ggplot(df, aes(Month, Value)) + 
  geom_bar(fill = "orange", size = .3, stat = "identity", position = "identity") +
  geom_smooth(data = df, aes(Month, Value, group = 1), method = "lm", 
              size = 2, color = "red") + 
  scale_x_date(breaks = "1 month", labels = date_format("%b-%Y"), 
               limits = as.Date(c('2011-01-01','2013-01-01')))

Bars in the ggplot goes over the other dates as well. I do get this warning message:

Warning message:
In qt((1 - level)/2, df) : NaNs produced

Is there a way to place the bin to the belonging date, rather than crossing over to other dates?

  • 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-16T20:36:58+00:00Added an answer on June 16, 2026 at 8:36 pm

    Simplified your code for plot. There is no need to write data frame name, x and y values in each geom.

    To change bar width, argument width= in geom_bar() can be used.

    ggplot(df, aes(Month, Value)) + 
      geom_bar(fill="orange",stat="identity",width=15)+
      geom_smooth( method="lm", size=2, color="red")+
      scale_x_date(breaks = "1 month", labels=date_format("%b-%Y"), limits = as.Date(c('2011-01-01','2013-01-01')))
    

    You get error message because your data frame contains only two values (you can’t do regression with just two values). If there really are only two values, then replace

    geom_smooth( method="lm", size=2, color="red")
    

    with

    geom_line(size=2, color="red")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame is like this: dput(xx) structure(list(TimeStamp = structure(c(15705, 15706), class
I have this data frame: dput(df2) structure(list(Receiver = structure(c(4L, 3L, 2L, 1L), .Label =
I have a fairly simple data.frame dput(x), below: x <- structure(list(variable = c(a, b,
I have a melted data.frame, dput(x), below: ## dput(x) x <- structure(list(variable = structure(c(1L,
Here's the data.frame in question : sample <- dput(df) structure(c(6, 5, 5, 4, 4,
dput(x) structure(list(Date = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L,
I'm trying to plot some date points: library(ggplot2) library(plyr) set.seed(1234) df <- data.frame( c1
working with a data frame x Date Val 1/1/2012 7 2/1/2012 9 3/1/2012 20
I have the following dataframe: > dput(py6s_pwc_16) structure(list(source = c(AERONET, BIGF, MODIS), ndvi_real =
I've got a similarity matrix between all cases and, in a separate data frame,

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.