title: Many "duplicated levels in factors are deprecated" warning with ggplot2
body: <p>I have made a function that can plot the loadings from many factor analyses at once, also when their variables do not overlap perfectly (or at all). It works fine, except that it generates a number of "duplicated levels in factors are deprecated" warning, and I don't understand why.</p>
  
  <p>The code allow should be reproducible.</p>
  
  <pre><code>library(devtools)
  source_url("https://raw.githubusercontent.com/Deleetdk/psych2/master/psych2.R")
  
  loadings.plot2 = function(fa.objects, fa.names="") {
    fa.num = length(fa.objects) #number of fas
  
    if (fa.names=="") {
      fa.names = str_c("fa.", 1:fa.num)
    }
    if (length(fa.names) != fa.num) {
      stop("Names vector does not match the number of factor analyses.")
    }
  
    #merge into df
    d = data.frame() #to merge into
    for (fa.idx in 1:fa.num) { #loop over fa objects
      loads = fa.objects[[fa.idx]]$loadings
      rnames = rownames(loads)
      loads = as.data.frame(as.vector(loads))
      rownames(loads) = rnames
      colnames(loads) = fa.names[fa.idx]
  
      d = merge.datasets(d, loads, 1)
    }
  
  
    #reshape to long form
    d2 = reshape(d,
                 varying = 1:fa.num,
                 direction="long",
                 ids = rownames(d))
    d2$time = as.factor(d2$time)
    d2$id = as.factor(d2$id)
    print(d2)
    print(levels(d2$time))
    print(levels(d2$id))
  
    #plot
    g = ggplot(reorder_by(id, ~ fa, d2), aes(x=fa, y=id, color=time)) +
        geom_point() +
        xlab("Loading") + ylab("Indicator") +
        scale_color_discrete(name="Analysis",
                             labels=fa.names)
  
    return(g)
  }
  
  fa1 = fa(iris[-5])
  fa2 = fa(iris[-c(1:50),-5])
  fa3 = fa(ability)
  fa4 = fa(ability[1:50,])
  
  loadings.plot2(list(fa1))
  loadings.plot2(list(fa1,fa2))
  loadings.plot2(list(fa1,fa2,fa3))
  loadings.plot2(list(fa1,fa2,fa3,fa4))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/oPVRH.png" alt="The example above, with 4 factor analyses"></p>
  
  <p>Plotting different numbers of factors give different numbers of errors.</p>
  
  <p>I have tried setting the variables <code>as.factor</code> before giving them to ggplot, but it didn't change anything.</p>
  
  <p>Any ideas? Perhaps related to <code>reorder_by()</code>? This function is needed to sort the data.frame, otherwise ggplot sorts them alphabetically, which is useless.</p>