OECDパッケージ02

OECD , ggplot2, RColorBrewer パッケージ

国名を日本語に

社会保障給付費の対GDP比

OECD加盟国の65歳以上の貧困率

  • 日本だけ色を変える(日本は7番目)

国コードと国名(日本語)を対応させる

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
code<-c(
"AND","アンドラ",
"ARE","アラブ首長国連邦",
"AFG","アフガニスタン",
"ATG","アンティグア・バーブーダ",
"AIA","アンギラ",
"ALB","アルバニア",
"ARM","アルメニア",
"AGO","アンゴラ",
"ATA","南極",
"ARG","アルゼンチン",
"ASM","アメリカ領サモア",
"AUT","オーストリア",
"AUS","オーストラリア",
"ABW","アルバ",
"ALA","オーランド諸島",
"AZE","アゼルバイジャン",
"BIH","ボスニア・ヘルツェゴビナ",
"BRB","バルバドス",
"BGD","バングラデシュ",
"BEL","ベルギー",
"BFA","ブルキナファソ",
"BGR","ブルガリア",
"BHR","バーレーン",
"BDI","ブルンジ",
"BEN","ベナン",
"BLM","サン・バルテルミー島",
"BMU","バミューダ諸島",
"BRN","ブルネイ・ダルサラーム",
"BOL","ボリビア多民族国",
"BES","ボネール、シント・ユースタティウスおよびサバ",
"BRA","ブラジル",
"BHS","バハマ",
"BTN","ブータン",
"BVT","ブーベ島",
"BWA","ボツワナ",
"BLR","ベラルーシ",
"BLZ","ベリーズ",
"CAN","カナダ",
"CCK","ココス(キーリング)諸島",
"COD","コンゴ民主共和国",
"CAF","中央アフリカ",
"COG","コンゴ共和国",
"CHE","スイス",
"CIV","コートジボワール",
"COK","クック諸島",
"CHL","チリ",
"CMR","カメルーン",
"CHN","中華人民共和国 (中国)",
"COL","コロンビア",
"CRI","コスタリカ",
"CUB","キューバ",
"CPV","カボベルデ",
"CUW","キュラソー",
"CXR","クリスマス島",
"CYP","キプロス",
"CZE","チェコ",
"DEU","ドイツ",
"DJI","ジブチ",
"DNK","デンマーク",
"DMA","ドミニカ",
"DOM","ドミニカ共和国",
"DZA","アルジェリア",
"ECU","エクアドル",
"EST","エストニア",
"EGY","エジプト",
"ESH","西サハラ",
"ERI","エリトリア",
"ESP","スペイン",
"ETH","エチオピア",
"FIN","フィンランド",
"FJI","フィジー",
"FLK","フォークランド(マルビナス)諸島",
"FSM","ミクロネシア連邦",
"FRO","フェロー諸島",
"FRA","フランス",
"GAB","ガボン",
"GBR","イギリス",
"GRD","グレナダ",
"GEO","ジョージア",
"GUF","フランス領ギアナ",
"GGY","ガーンジー島",
"GHA","ガーナ",
"GIB","ジブラルタル",
"GRL","グリーンランド",
"GMB","ガンビア",
"GIN","ギニア",
"GLP","グアドループ島",
"GNQ","赤道ギニア",
"GRC","ギリシャ",
"SGS","サウスジョージア・サウスサンドウィッチ諸島",
"GTM","グアテマラ",
"GUM","グアム",
"GNB","ギニアビサウ",
"GUY","ガイアナ",
"HKG","香港",
"HMD","ハード島・マクドナルド諸島",
"HND","ホンジュラス",
"HRV","クロアチア",
"HTI","ハイチ",
"HUN","ハンガリー",
"IDN","インドネシア",
"IRL","アイルランド",
"ISR","イスラエル",
"IMN","マン島",
"IND","インド",
"IOT","イギリス領インド洋地域",
"IRQ","イラク",
"IRN","イラン・イスラム共和国",
"ISL","アイスランド",
"ITA","イタリア",
"JEY","ジャージー島",
"JAM","ジャマイカ",
"JOR","ヨルダン",
"JPN","日本",
"KEN","ケニア",
"KGZ","キルギス",
"KHM","カンボジア",
"KIR","キリバス",
"COM","コモロ",
"KNA","セントクリストファー・ネビス",
"PRK","朝鮮民主主義人民共和国 (北朝鮮)",
"KOR","大韓民国 (韓国)",
"KWT","クウェート",
"CYM","ケイマン諸島",
"KAZ","カザフスタン",
"LAO","ラオス人民民主共和国",
"LBN","レバノン",
"LCA","セントルシア",
"LIE","リヒテンシュタイン",
"LKA","スリランカ",
"LBR","リベリア",
"LSO","レソト",
"LTU","リトアニア",
"LUX","ルクセンブルク",
"LVA","ラトビア",
"LBY","リビア",
"MAR","モロッコ",
"MCO","モナコ",
"MDA","モルドバ共和国",
"MNE","モンテネグロ",
"MAF","サン・マルタン島",
"MDG","マダガスカル",
"MHL","マーシャル諸島",
"MKD","マケドニア旧ユーゴスラビア共和国",
"MLI","マリ",
"MMR","ミャンマー",
"MNG","モンゴル",
"MAC","マカオ",
"MNP","北マリアナ諸島",
"MTQ","マルティニク",
"MRT","モーリタニア",
"MSR","モントセラト",
"MLT","マルタ",
"MUS","モーリシャス",
"MDV","モルディブ",
"MWI","マラウイ",
"MEX","メキシコ",
"MYS","マレーシア",
"MOZ","モザンビーク",
"NAM","ナミビア",
"NCL","ニューカレドニア",
"NER","ニジェール",
"NFK","ノーフォーク島",
"NGA","ナイジェリア",
"NIC","ニカラグア",
"NLD","オランダ",
"NOR","ノルウェー",
"NPL","ネパール",
"NRU","ナウル",
"NIU","ニウエ",
"NZL","ニュージーランド",
"OMN","オマーン",
"PAN","パナマ",
"PER","ペルー",
"PYF","フランス領ポリネシア",
"PNG","パプアニューギニア",
"PHL","フィリピン",
"PAK","パキスタン",
"POL","ポーランド",
"SPM","サンピエール・ミクロン島",
"PCN","ピトケアン",
"PRI","プエルトリコ",
"PSE","パレスチナ",
"PRT","ポルトガル",
"PLW","パラオ",
"PRY","パラグアイ",
"QAT","カタール",
"REU","レユニオン",
"ROU","ルーマニア",
"SRB","セルビア",
"RUS","ロシア",
"RWA","ルワンダ",
"SAU","サウジアラビア",
"SLB","ソロモン諸島",
"SYC","セーシェル",
"SDN","スーダン",
"SWE","スウェーデン",
"SGP","シンガポール",
"SHN","セントヘレナ・アセンションおよびトリスタンダクーニャ",
"SVN","スロベニア",
"SJM","スバールバル諸島・ヤンマイエン島",
"SVK","スロバキア",
"SLE","シエラレオネ",
"SMR","サンマリノ",
"SEN","セネガル",
"SOM","ソマリア",
"SUR","スリナム",
"SSD","南スーダン",
"STP","サントメ・プリンシペ",
"SLV","エルサルバドル",
"SXM","シント・マールテン(オランダ領)",
"SYR","シリア・アラブ共和国",
"SWZ","スワジランド",
"TCA","タークスカイコス諸島",
"TCD","チャド",
"ATF","フランス領南方・南極地域",
"TGO","トーゴ",
"THA","タイ",
"TJK","タジキスタン",
"TKL","トケラウ諸島",
"TLS","東ティモール",
"TKM","トルクメニスタン",
"TUN","チュニジア",
"TON","トンガ",
"TUR","トルコ",
"TTO","トリニダード・トバゴ",
"TUV","ツバル",
"TWN","台湾",
"TZA","タンザニア",
"UKR","ウクライナ",
"UGA","ウガンダ",
"UMI","合衆国領有小離島",
"USA","アメリカ合衆国",
"URY","ウルグアイ",
"UZB","ウズベキスタン",
"VAT","バチカン市国",
"VCT","セントビンセント・グレナディーン",
"VEN","ベネズエラ・ボリバル共和国",
"VGB","イギリス領バージン諸島",
"VIR","アメリカ領バージン諸島",
"VNM","ベトナム",
"VUT","バヌアツ",
"WLF","ワリスフュチュナ",
"WSM","サモア",
"YEM","イエメン",
"MYT","マヨット島",
"ZAF","南アフリカ共和国",
"ZMB","ザンビア",
"ZWE","ジンバブエ")
#
country_code<-matrix(code, ncol=2, byrow=T)

データの入手~グラフ

グラフ1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
library(OECD)
dataset_list <-get_datasets()
#social expenditure(社会保障給付費)を含むデータセットを検索
search_dataset("social expenditure", data = dataset_list)
dataset<-"SOCX_AGG"
data <-get_data_structure(dataset)
data$VAR_DESC
#
filter_list <-list(c("10_20"),c("1","2","3","4","5","6","7","8","9"),c("0"),c("0"),c("PCT_GDP"))
df <-get_dataset(dataset = dataset,filter =filter_list, start_time =2011,end_time =2011)
head(df)
df1<-data.frame(COUNTRY=df$COUNTRY,BRANCH=df$BRANCH,Value=df$obsValue)
#国コード -> 国名
for (i in 1:nrow(country_code) ) {
df1$COUNTRY <-gsub(country_code[i,1],country_code[i,2],df1$COUNTRY )
}
#
#
library(ggplot2)
library(RColorBrewer)
cols = brewer.pal(9, "Set3")
#OECD平均のデータの積み重ね順を直すための工夫
df1<-df1[order(df1$BRANCH),]
#国名をvalueの降順にするための工夫
#tapply(df1$Value,df1$COUNTRY, sum)
zyun<-sort(tapply(df1$Value,df1$COUNTRY, sum),decreasing = TRUE )
#attr(zyun, "dimnames")[[1]]
#png("SOCX_AGG02j.png",width=800,height=600)
p <- ggplot(df1, aes(x=COUNTRY, y=Value))
p + geom_bar(stat="identity", aes(fill=BRANCH)) +
#国名をvalueの降順にする
scale_x_discrete(limits=attr(zyun, "dimnames")[[1]]) +
scale_fill_manual(breaks=c("1","2","3","4","5","6","7","8","9"),
labels=c("高齢者", "遺族","障害", "医療",
"家族", "積極的雇用政策","失業", "住宅", "その他"),
values=cols,
guide = guide_legend(reverse=T)) +
labs(x="",y="",title="社会保障給付費の対GDP比(OECD諸国:2011年)",fill="") +
#国名の表示を斜めに
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
#下の余白をなくす。
scale_y_continuous(expand =c(0,0),limits=c(0,32) )
#dev.off()
グラフ2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#library(OECD)
#dataset_list <-get_datasets()
#Pensions at a Glanceを含むデータセットを検索
search_dataset("Pensions at a Glance", data = dataset_list)
dataset<-"PAG"
data <-get_data_structure(dataset)
data$VAR_DESC
# id description
#1 COU Country
#2 IND Indicator
#3 YEAR Year
#4 OBS_VALUE Observation Value
#5 TIME_FORMAT Time Format
#6 OBS_STATUS Observation Status
#7 UNIT Unit
#8 POWERCODE Unit multiplier
#9 REFERENCEPERIOD Reference period
#
#入手する国はデータのある国すべて
#data$COU$id とする
#
filter_list <-list(data$COU$id,c("PEN24A"))
df <-get_dataset(dataset = dataset,filter =filter_list, start_time =2014,end_time =2014)
df
#
for (i in 1:nrow(country_code) ) {
df$COU <-gsub(country_code[i,1],country_code[i,2],df$COU )
}
#
library(ggplot2)
#png("PAG01j.png",width=800,height=600)
p <- ggplot(df, aes(x=COU, y=obsValue))
p + geom_bar(stat="identity") +
scale_x_discrete(limits=df[order(df$obsValue,decreasing = TRUE),]$COU) +
labs(x="",y="",title="OECD加盟国の65歳以上の貧困率(2014年)") +
#国名の表示を斜めに
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
#下の余白をなくす。
scale_y_continuous(expand =c(0,0),limits=c(0,52) )
#dev.off()
  • 日本だけ色を変える
1
2
3
4
5
6
7
8
9
10
11
#png("PAG02j.png",width=800,height=600)
p <- ggplot(df, aes(x=COU, y=obsValue))
#日本をピンク、他はグレー
p + geom_bar(stat="identity",fill=c(rep("gray",6),"pink",rep("gray",length(df$COU)-7)) ) +
scale_x_discrete(limits=df[order(df$obsValue,decreasing = TRUE),]$COU) +
labs(x="",y="",title="OECD加盟国の65歳以上の貧困率(2014年)") +
#国名の表示を斜めに
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
#下の余白をなくす。
scale_y_continuous(expand =c(0,0),limits=c(0,52) )
#dev.off()