2017-09-22 8 views
0

私はy軸に沿った位置推定データとx軸に沿った基本的なカウントスケールとの棒グラフ(ggplot2を使用)を生成しようとしています。ggplot2 - 重み付け値によるグラフの並べ替え

Data <- data.frame(locations = c("A","B","C","D"...), estimates = c(200, 300, 400, 200...) 

が、私はそのように、私は私のggplot2コード

library(ggplot2) 
    ggplot(Data, aes(locations, weight = estimates))+ 
     geom_bar()+ 
     coord_flip() 

を実行

library(dplyr) 
    Data <- Data %>% arrange(estimates) 

推計によると、私のデータを配置するdplyrを使用しかし、結果のプロット:私のデータはそうのように構成されていますそのような場合、バーは見積もりに従って注文されていません。

enter image description here

答えて

1

dplyrを使用しても意味がありません。 scale_x_discrete(limits = Data$locations[order(Data$estimates)])

library(ggplot2) 

ggplot(Data, aes(locations, weight = estimates))+ 
     geom_bar()+ 
     coord_flip() + 
     scale_x_discrete(limits = Data$locations[order(Data$estimates)]) 

enter image description here

:あなたがしなければならないのは、 estimatesを注文 locations対応抽出し、例えば、 scale_x_discreteにそれを渡すことです
関連する問題