各国枪支数量1

gun <- fread("./各国枪支数量csvData.csv") 
gun
##               country  firearms per100 military  lawEnf    pop2022
##   1:    United States 393347000  120.5  4535380 1016000 338289.857
##   2: Falkland Islands      2000   62.1       NA      30      3.780
##   3:            Yemen  14859000   52.8    28500      NA  33696.614
##   4:    New Caledonia    115000   42.5       NA     700    289.950
##   5:           Serbia   2719000   39.1   384422   53100   7221.365
##  ---                                                              
## 212:      Timor-Leste      3000    0.3     2527    4000   1341.296
## 213:      South Korea     79000    0.2  2688020  115000  51815.810
## 214:  Solomon Islands      1000    0.2       NA      70    724.273
## 215:        Indonesia     82000    0.0  1711450  429000 275501.339
## 216:           Taiwan     10000    0.0  2022150   76000  23893.394
crim <- fread("./各国犯罪率.csv", header = T)
crim
##      Country Name   2020   2019   2018   2017   2016
##   1:      Jamaica 44.949 45.450 43.920 56.388 46.589
##   2:     Honduras 36.327 42.007 38.926 40.980 55.551
##   3: South Africa 33.462 36.417 36.399 35.671 33.832
##   4:       Mexico 28.371 28.737 29.071 25.709 19.913
##   5:    St. Lucia 28.318 25.165 20.342 27.079 16.664
##  ---                                                
## 141:         Guam  0.000  4.184  0.000  0.000  0.000
## 142:         Iran  0.000  0.000  2.194  0.000  0.000
## 143:          UAE  0.000  0.655  0.000  0.000  0.000
## 144:     Cameroon  0.000  0.000  0.000  1.388  1.154
## 145:        Ghana  0.000  0.000  0.000  2.091  1.928
ggthemr::ggthemr()
melt(crim, id = 1)[,
                   `:=`("variable" = as.integer(as.character(variable)),
                        "Country" = forcats::fct_reorder(`Country Name`, value)
                        )
][] |> 
        ggplot(mapping = aes(value, Country)) +
        geom_point() +
        labs(x = "犯罪率(%)", y = "")  +
        gganimate::transition_time(variable) +
        ggtitle("各国犯罪率变化({frame_time}年)")+
        theme(axis.title.x = element_text(family = "yahei")) ->p
gganimate::animate(p, width = 800, height = 1500)

# gganimate::anim_save("./res.gif", p, width = 800, height = 1500,res = 100)

  1. https://worldpopulationreview.com/↩︎