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左右,降了很多。

說下印度半島,戰火一直在增加。


分享到:


相關文章: