2017-04-21 24 views
0

に注文を取得私は、コードを使用して標準的な棒グラフをプロットすることを試みた:ggplot:凡例レベル、右のX軸

dat2<-data.frame(Ramp = rep(c("Low","Mid","MidHigh", "High"),each = 2), 
      score=rep(c("Average Score", "Top Score"), 2), 
      score.1=c(23.89,23.89,7.31,2.54,10.18,8.70, 
         3.17,2.00)) 

    plot2<- ggplot(data=dat2,aes(x=score, y=score.1, fill = Ramp)) + 
     geom_bar(stat="identity", position = position_dodge(), 
       width = .8) + 
     theme_classic() 

    colour2<- scale_fill_grey(limits = c("Low","Mid","MidHigh","High")) 

    plot2 + colour2     

これは、凡例が正しい順序になっているプロットをもたらしますx軸の要素は正しい順序ではありません。凡例の順序に合わせて変更するにはどうすればよいですか?

プロットは、現在のようになります。レベルを指定して、因子変数に

enter image description here

+1

[ggplot2棒グラフでオーダーバー(http://stackoverflow.com/questions/5208679/order-bars-in-ggplot2-bar-graph)の可能性の重複 – Jimbou

答えて

0

変更ランプ変数。

RampF <- factor(c("Low","Mid","MidHigh", "High"), levels = c("Low","Mid","MidHigh", "High")) 

dat2<-data.frame(Ramp = rep(RampF,each = 2), 
       score=rep(c("Average Score", "Top Score"), 2), 
       score.1=c(23.89,23.89,7.31,2.54,10.18,8.70, 
          3.17,2.00)) 

plot2<- ggplot(data=dat2,aes(x=score, y=score.1, fill = Ramp)) + 
    geom_bar(stat="identity", position = position_dodge(), 
      width = .8) + 
    theme_classic() 

colour2<- scale_fill_grey(limits = c("Low","Mid","MidHigh","High")) 

plot2 + colour2 
関連する問題