04.08 R的ggplot2画gif图——看恐怖袭击事件

我们从kaggle下载了恐怖袭击的数据,有10几万行的数据。用ggplot2进行了画图,并用gganimate包进行gif。

加载包:

library(ggplot2)

library(gganimate)

library(RColorBrewer)

#代码:

R的ggplot2画gif图——看恐怖袭击事件

terriost attack distribution

ggplot()+borders("world",color="gray85",fill="gray80")+geom_point(data=terriost,aes(longitude,latitude,frame=iyear,color=weaptype1_txt))+labs(title="世界恐怖主义袭击",size=15,color="#FF7F00")+theme(text=element_text(color="#EEEEEE"),plot.title=element_text(size=40,color="#FF7F00"),panel.grid=element_blank(),panel.background=element_rect(fill="#2171B5"),legend.background = element_blank(),legend.text=element_text(size=8,color="#FF7F00"),legend.title=element_blank(),legend.key = element_blank(),axis.text=element_blank(),axis.title=element_blank(),legend.position= c(0.25,0.35),legend.direction = "vertical")+annotate(geom="text",label="Data comes from kaggle,created by Guohua Chen",x=70,y=-80,size=4,color="#F03B20")->map

animation::ani.options(interval=0.15,ani.width=1200,ani.height=750,units="in") # 设置动画

gganimate::gganimate(map) # 生成gif

说明:

从图上看,恐怖袭击每年都在增加。尤其是中东地区,到了2000年后,恐怖袭击越来越严重。而南美洲在1980年左右恐怖袭击很多,到了2000年后基本上消失了,说明很多国家得到了解放。

非洲中部到了2000年后恐怖袭击也很多。

俄罗斯、加拿大、中国、澳大利亚基本上没有恐怖主义。

美国到了2016左右,恐怖主义增加了很多。

欧洲战火不断,到了2016左右,降了很多。

说下印度半岛,战火一直在增加。


分享到:


相關文章: