2016-07-17 6 views
1

商品、会計期間、トランザクションを1つの表に示すデータセットがあります。ggplotダッジ・チャートを期待して積み重ね棒を作成する

app$FISCAL_PERIOD <-(201604,201604,201604,201605,201605,201605,201606,201606,201606,201607,201607,201607,201608,201608,201608,201609,201609,201610,201610,201611,201611) 

app$Product <- c("Product 1","Product 3","Other","Product 1","Product 3","Other","Product 1","Product 3","Other","Product 1","Product 3","Other","Product 1","Product 3","Other","Product 2","Product 3","Product 2","Product 3","Product 2","Product 3") 

app$sum_trans<-c(78,23410,1946,84,29532,417,16,30364,129,305,32386,584,424,20873,274,20,20929,470,19261,10,6131) 

私はこれを実行すると、私は私が期待していたチャートを取得し、棒グラフ「かわし」:

ggplot(data=app, aes(x=FISCAL_PERIOD, y=sum_trans, fill=Product)) + geom_bar(stat="identity", position=position_dodge(), colour="black")

をしかし、私はこれを実行すると、私はある積み上げ棒グラフを取得私は必要ないものを:

ggplot(data=app, aes(x=Product, y=sum_trans, fill=FISCAL_PERIOD)) + geom_bar(stat="identity", position=position_dodge(), colour="black")

答えて

0

ggplotが要因バリなどFISCAL_PERIOD変数を理解していないので、これがケースかもしれませんできる。これで修正が行われます。

ggplot(data=app, aes(x=Product, y=sum_trans, fill=as.factor(FISCAL_PERIOD))) + 
geom_bar(stat="identity", position="dodge", colour="black") 
関連する問題