title: Helps plot the graph when the variable has equal values
body: <p>The code below generates a graph with dots and a &quot;prediction&quot; line, so to speak. In this case, it is generating for <code>dmda=01/07</code>. However, I cannot generate a graph for the day 02/07 or 03/07. From what I understand it is due to the values ​​of the variable <code>datas</code> being equal. For example, the variable <code>datas</code> for 01/07 is: 12, 12, 16 and 18 - in this case it generates the graph. For 02/07 it is 13, 13, 13 and for 03/07 is 11 and 11. Because these values ​​are equal, the <code>nls function</code> does not work. So what I would like to do is:</p>
  <p>When the values ​​of the variable <code>datas</code> are equal, the code would not need to go through the <code>nls function</code>, but would generate the graph with the red dot being the value obtained by the variable <code>datas</code>, that is, if it is for 03/07, the graph would have the line of &quot;predction&quot; going to 11 same. I put an image to illustrate.</p>
  <p>I appreciate any help!</p>
  <pre><code>library(dplyr)
  library(lubridate)
  library(tidyverse)
  
  df1 &lt;- structure(
    list(date1 = c(&quot;2021-06-28&quot;,&quot;2021-06-28&quot;,&quot;2021-06-28&quot;,&quot;2021-06-28&quot;,&quot;2021-06-28&quot;,
                   &quot;2021-06-28&quot;,&quot;2021-06-28&quot;,&quot;2021-06-28&quot;),
         date2 = c(&quot;2021-04-02&quot;,&quot;2021-04-03&quot;,&quot;2021-04-08&quot;,&quot;2021-04-09&quot;,&quot;2021-04-10&quot;,&quot;2021-07-01&quot;,&quot;2021-07-02&quot;,&quot;2021-07-03&quot;),
         Week= c(&quot;Friday&quot;,&quot;Saturday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Monday&quot;),
         DR01 = c(14,11,14,13,13,14,0,0), DR02= c(14,12,16,17,13,12,0,0),DR03= c(19,15,14,13,13,12,0,0),
         DR04 = c(15,14,13,13,16,12,13,0),DR05 = c(15,14,15,13,16,12,13,11),
         DR06 = c(21,14,13,13,15,16,13,11),DR07 = c(12,15,14,14,19,14,13,11)),
    class = &quot;data.frame&quot;, row.names = c(NA, -8L))
  
  dmda&lt;-&quot;2021-07-01&quot;
  
  datas&lt;-df1 %&gt;%
    filter(date2 == ymd(dmda)) %&gt;%
    summarize(across(starts_with(&quot;DR&quot;), sum)) %&gt;%
    pivot_longer(everything(), names_pattern = &quot;DR(.+)&quot;, values_to = &quot;val&quot;) %&gt;%
    mutate(name = as.numeric(name))
  colnames(datas)&lt;-c(&quot;Days&quot;,&quot;Numbers&quot;)
  
  dif &lt;- as.Date(dmda) - as.Date(df1$date1[1]) + 1
  datas &lt;- datas[dif:max(datas$Days, na.rm = TRUE),]
  
  plot(Numbers ~ Days, xlim=c(0,8), ylim=c(0,20), data = datas,xaxs='i')
  mod &lt;- nls(Numbers ~ b1*Days^2+b2,start = list(b1 = 0,b2 = 0), data = datas)
  new.data &lt;- data.frame(Days = with(datas, seq(min(Days),max(Days),len = 45)))
  new.data &lt;- rbind(0, new.data)
  lines(new.data$Days, predict(mod, newdata=new.data))
  points(0, coef(mod)[2], col=&quot;red&quot;, pch=19, cex=1.2, xpd=TRUE)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/J8mY3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J8mY3.png" alt="enter image description here" /></a></p>
  <p><strong>Example for 03/07</strong>
  <a href="https://i.stack.imgur.com/GCf86.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GCf86.png" alt="enter image description here" /></a></p>