title: R shift scale at x axis date with a non-continuous sequence of time
body: <p>I have a time serie data from two consecutive years (2017-2018), from january to december of each year. Then I need to plot the data from sept-17 to april-18.</p>
  
  <p>I could do it with a very hand-made code, however I realize it could be done very much straightforward way with the packages availabe today for managing dates on plots (packages "scales", "lubridate", etc.)</p>
  
  <p>Can someone help me to simplify my work for doing the second plot?
  I will really appreciate it.</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code>  suppressWarnings(suppressMessages(library("tidyverse", quietly = T)))
  
  
    dat &lt;- tibble(
      date = seq(as.Date("2017-01-01"), as.Date("2018-12-31"), by=1),
      var = rgamma(length(date), shape=2, scale=2)) %&gt;% 
      mutate(year = lubridate::year(date),
             month = lubridate::month(date), 
             julian = lubridate::yday(date))
    dat
  #&gt; # A tibble: 730 x 5
  #&gt;    date         var  year month julian
  #&gt;    &lt;date&gt;     &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;  &lt;dbl&gt;
  #&gt;  1 2017-01-01 12.9   2017     1      1
  #&gt;  2 2017-01-02  6.69  2017     1      2
  #&gt;  3 2017-01-03  6.11  2017     1      3
  #&gt;  4 2017-01-04  1.68  2017     1      4
  #&gt;  5 2017-01-05  1.22  2017     1      5
  #&gt;  6 2017-01-06 10.2   2017     1      6
  #&gt;  7 2017-01-07  5.13  2017     1      7
  #&gt;  8 2017-01-08  4.61  2017     1      8
  #&gt;  9 2017-01-09  3.79  2017     1      9
  #&gt; 10 2017-01-10  1.11  2017     1     10
  #&gt; # … with 720 more rows
  
    dat %&gt;%
      ggplot() +
      geom_line(aes(julian, var, color = factor(month), linetype=factor(year))) 
  </code></pre>
  
  <p><img src="https://i.imgur.com/WKzAWP5.png" alt=""></p>
  
  <pre class="lang-r prettyprint-override"><code>  dat %&gt;%
      filter((year == 2017 &amp; month %in% c("9","10", "11", "12"))|
               (year == 2018 &amp; month %in% c("1", "2", "3"))) %&gt;%
      mutate(julian_AWS = ifelse(julian&gt;=244, julian-243, julian+123)) %&gt;% 
      ggplot() +
      geom_line(aes(julian_AWS, var, color = factor(month), linetype=factor(year)))+
      scale_x_continuous(breaks = c(1,#S
                                    31,#O
                                    61,#N
                                    91,#D
                                    121,#E
                                    151,#F
                                    181),#M
                         labels = c("Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar"))+
      theme(axis.text.x=element_text(hjust=-1))
  </code></pre>
  
  <p><img src="https://i.imgur.com/8EByEU5.png" alt=""></p>
  
  <p><sup>Created on 2019-05-05 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.2.1)</sup></p>