第9週

02/15(TH)  紛争と貧困の連鎖3

       紛争と貧困の連鎖を断ち切る方法

02/20(TU) Rでデータサイエンス9:まとめと演習 [準備]・[授業]

内容

library(tidyverse)
library(WDI)

France, United States, United Kingdom, Germany, Japan, Italy, Canada, and EU (non-enumerated member)

G7 <- c("FR", "US", "GB", "DE", "JP", "IT", "CA", "EU")
WDIsearch(string = "% of.*government", field = "name")
WDIcache()$series |> filter(grepl("MS.MIL.XPND.ZS", indicator, ignore.case=T) | grepl("SE.XPD.TOTL.GB.ZS", indicator, ignore.case=T) | grepl("SH.XPD.GHED.GE.ZS" , indicator, ignore.case=T) | grepl("SH.XPD.PUBL.GX.ZS", indicator, ignore.case=T))
df_government_expenditure <- WDI(country = G7, indicator = c(military = "MS.MIL.XPND.ZS", education = "SE.XPD.TOTL.GB.ZS", health = "SH.XPD.GHED.GE.ZS"))
df_government_expenditure |> distinct(country, iso2c)
write_csv(df_government_expenditure, "data/government_expenditure.csv")
df_government_expenditure <- read_csv("data/government_expenditure.csv")
Rows: 504 Columns: 7── Column specification ───────────────────────────────────────────────────
Delimiter: ","
chr (3): country, iso2c, iso3c
dbl (4): year, military, education, health
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
df_government_expenditure_long <- df_government_expenditure |> 
  pivot_longer(c(military, education, health))
df_government_expenditure_long
df_government_expenditure_long |> drop_na(value) |>
  ggplot(aes(year, fill = iso2c)) + geom_bar() + 
  labs(title = "変数ごとのデータ数")

df_government_expenditure_long |> drop_na(value) |>
  ggplot(aes(year, value, col = iso2c, linetype = name)) + geom_line()

df_government_expenditure_long |> drop_na(value) |>
  ggplot(aes(year, value, col = iso2c, linetype = name)) + geom_line(aes(size = iso2c)) + scale_size_manual(values = c(0.3,0.3,0.3,0.3,0.3,0.3,1.0,0.3))

df_government_expenditure_long |> drop_na(value) |>
  ggplot(aes(year, value, col = name)) + geom_line() +
  facet_wrap(~country)

df_government_expenditure_long |> drop_na(value) |>
  ggplot(aes(year, value, col = iso2c)) + geom_line() +
  facet_wrap(~name)

df_government_expenditure_long |> filter(year == 2020) |> drop_na(value) |>
  ggplot(aes(fct_rev(fct_inorder(country)), value)) + geom_col() + coord_flip() + labs(title = "難民の多い順", x = "") + facet_wrap(~name)

LS0tCnRpdGxlOiAiR0VTIDAwMSDmvJTnv5I5IgphdXRob3I6ICJILiBTdXp1a2kiCmRhdGU6ICJgciBTeXMuRGF0ZSgpYCIKb3V0cHV0OgogIGh0bWxfbm90ZWJvb2s6IGRlZmF1bHQKLS0tCgojIyDnrKw56YCxCgowMi8xNShUSCkgwqDntJvkuonjgajosqflm7Djga7pgKPpjpYzCgrjgIDjgIDjgIDjgIDjgIAgwqDntJvkuonjgajosqflm7Djga7pgKPpjpbjgpLmlq3jgaHliIfjgovmlrnms5UKCjAyLzIwKFRVKeOAgFLjgafjg4fjg7zjgr/jgrXjgqTjgqjjg7Pjgrk577ya44G+44Go44KB44Go5ryU57+S44CAW1vmupblgpldKGh0dHBzOi8vZHMtc2wuZ2l0aHViLmlvL2ludHJvMnIvZ2VzMDAxL2dlczAwMS1wcmVwLTkubmIuaHRtbCld44O7W+aOiOalrV0KCiMjIOWGheWuuQoKYGBge3J9CmxpYnJhcnkodGlkeXZlcnNlKQpsaWJyYXJ5KFdESSkKYGBgCgpGcmFuY2UsIFVuaXRlZCBTdGF0ZXMsIFVuaXRlZCBLaW5nZG9tLCBHZXJtYW55LCBKYXBhbiwgSXRhbHksIENhbmFkYSwgYW5kIEVVIChub24tZW51bWVyYXRlZCBtZW1iZXIpCgpgYGB7cn0KRzcgPC0gYygiRlIiLCAiVVMiLCAiR0IiLCAiREUiLCAiSlAiLCAiSVQiLCAiQ0EiLCAiRVUiKQpgYGAKCmBgYHtyfQpXRElzZWFyY2goc3RyaW5nID0gIiUgb2YuKmdvdmVybm1lbnQiLCBmaWVsZCA9ICJuYW1lIikKYGBgCgpgYGB7cn0KV0RJY2FjaGUoKSRzZXJpZXMgfD4gZm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