How to force specific order of the variables on the X axis?
<p>My question has to do with order of plot bars when using ggplot.</p>

<pre><code>EffectNames = c("Pull Back(A)","Hook(B)","Peg(C)","AB","BC","AC","ABC")
Half_Effect = c(10.4, 6.5, 5.6, 1.6, 0.98, .77, .65)
paretoData = cbind(EffectNames, Half_Effect)
paretoData = as.data.frame(paretoData)

ggplot(paretoData, aes(x = EffectNames, y = Half_Effect)) +
    geom_bar(stat = "identity") +
    geom_text(aes(label = Half_Effect), vjust = 1.5, colour = "white")
</code></pre>

<p>Result:
Bar heights are in following order</p>

<pre><code>1.6 0.65 0.77 0.98    6.5    5.6        10.4
 AB  ABC   AC   BC Hook(B) Peg(C) PullBack(A)
</code></pre>

<p>Bar heights are not in order seen in Half_Effect. How to force ordering of EffectNames to match descending order of Half_Effect? Can this be done in ggplot2?  Yes it can! See solution below.</p>

<pre><code>EffectNames=c( "Pull Back(A)","Hook(B)", "Peg(C)","AB", "BC", "AC", "ABC")
Half_Effect=c( 10.4,6.5,5.6,1.6,0.98,.77,.65 )
paretoData=data.frame(EffectNames, Half_Effect)
paretoData
paretoData$EffectNames = factor(paretoData$EffectNames, 
    levels=c("Pull Back(A)","Hook(B)", "Peg(C)","AB", "BC", "AC", "ABC"))
p=ggplot(paretoData, aes(x=EffectNames, y=Half_Effect)) +
geom_bar(stat="identity") +
geom_text(aes(label=Half_Effect), vjust=1.5, colour="white")
p
</code></pre>