title: R: replacing "pivot_longer" with "melt"
body: <p>In a previous question (<a href="https://stackoverflow.com/questions/70616536/r-adding-two-series-to-a-graph">R: Adding Two Series to a Graph</a>), I learned how to make the following graph:</p>
  <pre><code>library(ggplot2)
  library(dplyr)
  
  my_data = data.frame(var_1_col = &quot;red&quot;, var_2_col = &quot;green&quot;, var_1 = rnorm(8,10,10), var_2 = rnorm(8,5,1), name = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;))
  
    var_1_col var_2_col     var_1    var_2 name
  1       red     green 14.726642 4.676161    A
  2       red     green 11.011187 4.937376    B
  3       red     green 12.418489 5.869617    C
  4       red     green 21.935154 5.641106    D
  5       red     green 20.209498 6.193123    E
  6       red     green -5.339944 5.187093    F
  7       red     green 20.540806 3.895683    G
  8       red     green 21.619631 4.097438    H
  
  my_data %&gt;%
    select(-c(var_1_col, var_2_col)) %&gt;%
    pivot_longer(-name, names_to = &quot;variable&quot;, values_to = &quot;value&quot;) %&gt;%
    ggplot(., aes(x = name, y = value, label = name)) +
    geom_point(stat = 'identity', aes(color = variable), size = 6)  +
    scale_color_manual(
      name = &quot;Var 1 or Var 2&quot;,
      labels = c(&quot;Var 1&quot;, &quot;Var 2&quot;),
      values = c(&quot;#00ba38&quot;, &quot;#f8766d&quot;)
    ) +
    labs(title = &quot;Plot&quot;,
         subtitle = &quot;Plot: Dotplot&quot;) +
    coord_flip() +
    theme_bw()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/B9CQS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B9CQS.png" alt="enter image description here" /></a></p>
  <p><strong>My Question:</strong> Does anyone know if it is possible to replace the <code>pivot_longer</code> function in the above code using either functions from Base R, or from <code>reshape</code>/<code>reshape2</code>?</p>
  <p><strong>Here was my attempt:</strong></p>
  <pre><code>library(reshape)
  library(reshape2)
  
  my_data %&gt;%
    select(-c(var_1_col, var_2_col)) %&gt;%
    reshape2::melt(my_data, id.vars = &quot;name&quot;, measure.vars = c(&quot;var_1&quot;, &quot;var_2&quot;)) %&gt;%
    ggplot(., aes(x = name, y = value, label = name)) +
    geom_point(stat = 'identity', aes(color = variable), size = 6)  +
    scale_color_manual(
      name = &quot;Var 1 or Var 2&quot;,
      labels = c(&quot;Var 1&quot;, &quot;Var 2&quot;),
      values = c(&quot;#00ba38&quot;, &quot;#f8766d&quot;)
    ) +
    labs(title = &quot;Plot&quot;,
         subtitle = &quot;Plot: Dotplot&quot;) +
    coord_flip() +
    theme_bw()
  </code></pre>
  <p>But this produces the following error:</p>
  <pre><code>'names' attribute [7] must be the same length as the vector [3]
  </code></pre>
  <p>Can someone please show me how to fix this?</p>
  <p>Thanks!</p>