title: How to wrap around the polar coordinate limits in ggplot2?
body: <p>I have a circular space where angles 0 and 360 are equivalent. I want to plot rectangles in this space such that rectangles can cross this value. However, I am having trouble with ggplot2.</p>
  
  <pre><code>base &lt;- ggplot() +
    scale_x_continuous(breaks = seq(45, 360, 45), limits = c(0, 360)) +
    scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
    coord_polar(theta = "x", start = 1.5 * pi, direction = -1)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XEaur.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XEaur.png" alt="enter image description here"></a></p>
  
  <p><strong>1. Attempt to plot with values exceeding xlim:</strong></p>
  
  <pre><code>base + geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6), 
    color = "darkblue", fill = "steelblue")
  #&gt; Warning message:
  #&gt; Removed 1 rows containing missing values (geom_rect). 
  </code></pre>
  
  <p>All values outside of xlim are removed so this does not work.</p>
  
  <p><strong>2. Attempt to plot with rescaled values</strong></p>
  
  <pre><code>base + geom_rect(aes(xmin = 340, xmax = 380 %% 360, ymin = 0.4, ymax = 0.6), 
    color = "darkblue", fill = "steelblue")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/aELDw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aELDw.png" alt="enter image description here"></a>
  This at least produces a plot, but plots the opposite of what I want. Instead of going from 340 to 380 CCW, this plots 340 to 20 CW.</p>
  
  <p><strong>3. Attempt to plot as two conjoining elements</strong></p>
  
  <pre><code>  base + geom_rect(aes(xmin = c(350, 0), xmax = c(360, 10), ymin = 0.4, ymax = 0.6), 
      color = "darkblue", fill = "steelblue")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ea2HW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ea2HW.png" alt="enter image description here"></a></p>
  
  <p>This shows the rectangle where I want it, but this is not satisfying as a solution because of the stroke lines at angle 0/360 and because I now have to represent each rectangle as two rectangles.</p>
  
  <p><strong>4. Attempt 1 to use zooming rather than clipping</strong></p>
  
  <pre><code>ggplot() +
    scale_x_continuous(breaks = seq(45, 360, 45)) +
    scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
    coord_cartesian(xlim = c(0, 360)) +
    coord_polar(theta = "x", start = 1.5 * pi, direction = -1) +
    geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6), 
      color = "darkblue", fill = "steelblue")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/53DEP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/53DEP.png" alt="enter image description here"></a>
  This seems to lose the zooming and the limits.</p>
  
  <p><strong>5. Attempt 2 to use zooming rather than clipping</strong></p>
  
  <pre><code>ggplot() +
    scale_x_continuous(breaks = seq(45, 360, 45)) +
    scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
    coord_polar(theta = "x", start = 1.5 * pi, direction = -1) +
    coord_cartesian(xlim = c(0, 360)) +
    geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6), 
      color = "darkblue", fill = "steelblue")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/F7rNs.png" rel="noreferrer"><img src="https://i.stack.imgur.com/F7rNs.png" alt="enter image description here"></a>
  This accomplishes the zooming correctly, but overwrites the polar coordinate system.</p>
  
  <p>If anyone can provide a solution or ideas for this problem, I would really appreciate it. Again, I am looking for something that looks like #3 but without the inner stroke and without needing to use two rectangles.</p>
  
  <p>Edit: This <a href="https://stackoverflow.com/questions/35225461/zoom-scale-with-coord-polar">question</a> is related and also unanswered.</p>