title: manually add breaks to both x and y axis in ggplot2
body: <p>I've typically changed the scale breaks for continuous variables in ggplot2 using <code>scale_y_continuous</code> (or <code>scale_x_continuous</code>). I also usually set the axis limits using <code>coord_cartesian(xlim=)</code> (or <code>ylim=</code> for y axis). All that works just fine like in the following:</p>
  
  <pre><code>#Some example data
  set.seed(100)
  b&lt;-sample(1:10, 10)
  a&lt;-sample(1:10, 10)
  
  df&lt;-data.frame(a,b)
  
  #Graph without scales set (just default)
  library(ggplot2)
  ggplot(data=df, aes(a,b))+
    theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA, size=1), 
                       panel.grid.major = element_blank(), 
                       panel.grid.minor = element_blank(), 
                       axis.line = element_line(colour = "black"))+
    geom_text(aes(label=rownames(df)), color="black")
  </code></pre>
  
  <p>That produces the following plot with default scales:</p>
  
  <p><a href="https://i.stack.imgur.com/wldM5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wldM5.png" alt="enter image description here"></a></p>
  
  <p>If I want to adjust the x-axis to, say, 1-13 (i.e. 13 tick marks starting at 1 and ending at 13) I would do the following:</p>
  
  <pre><code>ggplot(data=df, aes(a,b))+
    theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA, size=1), 
                       panel.grid.major = element_blank(), 
                       panel.grid.minor = element_blank(), 
                       axis.line = element_line(colour = "black"))+
    geom_text(aes(label=rownames(df)), color="black")+
    scale_x_continuous(breaks = c(1,3,5,7,9,11,13))+
    coord_cartesian(xlim=c(0, 13))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/v4EYc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v4EYc.png" alt="enter image description here"></a></p>
  
  <p>...and for the y-axis...</p>
  
  <pre><code>ggplot(data=df, aes(a,b))+
    theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA, size=1), 
                       panel.grid.major = element_blank(), 
                       panel.grid.minor = element_blank(), 
                       axis.line = element_line(colour = "black"))+
    geom_text(aes(label=rownames(df)), color="black")+
    scale_y_continuous(breaks = c(1,3,5,7,9,11,13))+
    coord_cartesian(ylim=c(0, 13))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/aQa9T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aQa9T.png" alt="enter image description here"></a></p>
  
  <p>However, when I try to accomplish the very same scale adjustment for both axes at the same time, the output does not produce what I would expect (which is 1-13 on both the x and y axes).</p>
  
  <pre><code>ggplot(data=df, aes(a,b))+
    theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA, size=1), 
                       panel.grid.major = element_blank(), 
                       panel.grid.minor = element_blank(), 
                       axis.line = element_line(colour = "black"))+
    geom_text(aes(label=rownames(df)), color="black")+
    scale_y_continuous(breaks = c(1,3,5,7,9,11,13))+
    coord_cartesian(ylim=c(0, 13))+
    scale_x_continuous(breaks = c(1,3,5,7,9,11,13))+
    coord_cartesian(xlim=c(0, 13))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/xhEuA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xhEuA.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the x and y axis are not equivalent even though the exact same code has been passed to both axes. I don't understand why. Any help is much appreciated.</p>