title: split data frame and create stacked percent barplot in R
body: <p>My data frame looks like this:</p>
  
  <pre><code>plant  distance
  one      1
  one      3
  one      2
  one      3
  one      7
  one      4
  one      6
  one      8
  one      9
  two      1
  two      6
  two      4
  two      8
  two      5
  two      3
  three ……
  </code></pre>
  
  <p>I want to split <code>distance</code> of each level into groups by interval(for instance,interval=3). </p>
  
  <pre><code>plant  distance group
    one      1    1
    one      3    1
    one      2    1
    one      3    1
    one      7    3
    one      4    2
    one      6    2
    one      8    3
    one      9    3
    two      1    1
    two      6    2
    two      4    2
    two      8    3
    two      5    2
    two      3    1
    three ……
  </code></pre>
  
  <p>And compute percentage of each group</p>
  
  <pre><code>plant group percentage
  one     1     0.44
  one     2     0.22
  one     3     0.33
  two     1     0.33
  two     2     0.50
  two     3     0.17
  three ……
  </code></pre>
  
  <p>Finally, plot the percentages of each level of each group similar like this:
  <img src="https://i.stack.imgur.com/95Y5W.png" alt="enter image description here"></p>
  
  <p>and I do not know how to split each level by interval. Sorry for my English! Thank you for your help!</p>