- #変数barにggplotをdataデータを基にして適用
- bar <- ggplot()+
- #geom_pointで棒グラフの指定、横軸はregionをhouseholdsの値を参照し昇順に並び替えたもの、縦軸はH27のデータを用いる。
- geom_bar(data = data,mapping = aes(x =reorder(region,-households),y=households),stat="identity")
- #bar0.pngとして出力
- ggsave(file="bar0.png",plot = abc,width = 30,height = 5)
- abc <- ggplot()+
- #地方ごとに色を指定するfill=districtを追加
- geom_bar(data = data,mapping = aes(x =reorder(region,-households),y=households,fill=region),stat="identity")
- ggsave(file="bar1.png",plot = abc,width = 30,height = 5)
- abc <- ggplot()+
- #regionをdistrictに変更
- geom_bar(data = data,mapping = aes(x =reorder(district,-households),y=households,fill=district),stat="identity")
- ggsave(file="bar2.png",plot = abc,width = 30,height = 5)
- abc <- ggplot()+
- #position="fill"を追加
- geom_bar(data = data,mapping = aes(x =reorder(district,-households),y=households,fill=district),stat="identity",position="fill")
- ggsave(file="bar3.png",plot = abc,width = 30,height = 5)
- abc <- ggplot()+
- geom_bar(data = data,mapping = aes(x =reorder(district,-households),y=households,fill=district),stat="identity")+
- #coord_polarを追加
- coord_polar()
- ggsave(file="bar5.png",plot = abc,width = 5,height = 5)