title: relevel factors and reorder factors using tidyverse in R
body: <p>I want to use the functions <em><strong>relevel()</strong></em> and <em><strong>reorder()</strong></em> in my data frame. I understand how relevel works but I do not understand why I do not see the change of the levels in my data.frame. For example imagine that I have the iris dataset</p>
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  
  head(iris)
  #&gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
  #&gt; 1          5.1         3.5          1.4         0.2  setosa
  #&gt; 2          4.9         3.0          1.4         0.2  setosa
  #&gt; 3          4.7         3.2          1.3         0.2  setosa
  #&gt; 4          4.6         3.1          1.5         0.2  setosa
  #&gt; 5          5.0         3.6          1.4         0.2  setosa
  #&gt; 6          5.4         3.9          1.7         0.4  setosa
  
  
  iris$Species &lt;- factor(iris$Species, levels = c(&quot;versicolor&quot;,&quot;setosa&quot;,&quot;virginica&quot;), 
                         labels = c(&quot;versicolor&quot;,&quot;setosa&quot;,&quot;virginica&quot;))
  </code></pre>
  <p><sup>Created on 2022-04-12 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v2.0.1)</sup></p>
  <p>I can use this function to change the order of the levels
  or this function in dplyr :</p>
  <pre class="lang-r prettyprint-override"><code>iris %&gt;% 
    mutate(Species=factor(Species)) %&gt;% 
    mutate(Species=fct_relevel(Species,c(&quot;versicolor&quot;,&quot;setosa&quot;,&quot;virginica&quot;))) %&gt;% 
    head()
  #&gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
  #&gt; 1          5.1         3.5          1.4         0.2  setosa
  #&gt; 2          4.9         3.0          1.4         0.2  setosa
  #&gt; 3          4.7         3.2          1.3         0.2  setosa
  #&gt; 4          4.6         3.1          1.5         0.2  setosa
  #&gt; 5          5.0         3.6          1.4         0.2  setosa
  #&gt; 6          5.4         3.9          1.7         0.4  setosa
  </code></pre>
  <p><sup>Created on 2022-04-12 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v2.0.1)</sup>
  What i do not get is that while i see the change in the levels in my data set, when i call my data set i do not see the change of the order and this is essential to me.
  This is what i see</p>
  <pre><code>Species
  setosa
  ...
  versicolor
  ...
  virginica
  ...
  </code></pre>
  <p>This is what i want to see</p>
  <pre><code>Species
  versicolor
  ...
  setosa
  ...
  virginica
  ...
  </code></pre>
  <p>Any help to  actually change the order with tidyverse is appreciated.</p>