My question is about the order of the graphs when using ggplot.
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")
Result: Bar height in the following order
1.6 0.65 0.77 0.98 6.5 5.6 10.4 AB ABC AC BC Hook(B) Peg(C) PullBack(A)
Half_Effect does not display bar heights. How do I force EffectNames to descend in Half_Effect? Can this be done in ggplot2? Yes it can! See Solution below.
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