R語言使用gganimate創(chuàng)建可視化動圖_第1頁
R語言使用gganimate創(chuàng)建可視化動圖_第2頁
R語言使用gganimate創(chuàng)建可視化動圖_第3頁
R語言使用gganimate創(chuàng)建可視化動圖_第4頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

第R語言使用gganimate創(chuàng)建可視化動圖目錄前言加載R包,數(shù)據(jù)ggplot2繪制gganimate動態(tài)參考資料

前言

介紹一個主要用于繪制動畫的ggplot2的擴展包---gganimate包。

HansRosling的關于NewInsightsonPoverty的TED演講絕對是對我影響最大的幾個TED之一,原來數(shù)據(jù)可以這樣展示,,,可視化可以這樣炫,,,故事可以這樣講...

下面嘗試使用gganimate包和gapminder數(shù)據(jù)集,實現(xiàn)類似可視化過程。

加載R包,數(shù)據(jù)

#R包安裝

install.packages("devtools")

library(devtools)

install_github("thomasp85/gganimate")

install.packages("gapminder")

library(gganimate)

library(gapminder)

#查看數(shù)據(jù)

head(gapminder)

#Atibble:6x6

countrycontinentyearlifeExppopgdpPercap

fctfctintdblintdbl

1AfghanistanAsia195228.88425333779.

2AfghanistanAsia195730.39240934821.

3AfghanistanAsia196232.010267083853.

4AfghanistanAsia196734.011537966836.

5AfghanistanAsia197236.113079460740.

6AfghanistanAsia197738.414880372786.

數(shù)據(jù)集包括全球主要國家在1952-2007年的人均GDP增長、預期壽命以及人口增長的數(shù)據(jù)。

ggplot2繪制

使用ggplot2繪制

theme_set(theme_bw())

p-ggplot(gapminder,

aes(x=gdpPercap,y=lifeExp,size=pop,colour=country))+

geom_point(show.legend=FALSE,alpha=0.7)+

scale_color_viridis_d()+

scale_size(range=c(2,12))+

scale_x_log10()+

labs(x="GDPpercapita",y="Lifeexpectancy")

p

gganimate動態(tài)

1.transition_time()核心函數(shù),添加動態(tài)

p+transition_time(year)+

labs(title="Year:{frame_time}")

2按需設置

1)添加小尾巴

p+transition_time(year)+

labs(title="Year:{frame_time}")+

shadow_wake(wake_length=0.1,alpha=FALSE)

2)原數(shù)據(jù)做背景

p+transition_time(year)+

labs(title="Year:{frame_time}")+

shadow_mark(alpha=0.3,size=0.5)

參考資料

/en/blog/gganimate-how-to-create-plots-with-beautiful-animation-in-r/

/talks/hans_rosling_the_best_

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論