单位GDP与寿命的关系统计绘图

library(ggplot2)
library(gganimate)
theme_set(theme_bw())
library(gapminder)
head(gapminder)
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 = "GDP per capital", y = "Life expectancy")
p

通过不同州的时间数据进行转换

library(ggplot2)
library(gganimate)
theme_set(theme_bw())
library(gapminder)
head(gapminder)
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 = "GDP per capital", y = "Life expectancy")
p + transition_time(year) +labs(title = "Year: {frame_time}")

根据不同大洲创建不同面:

library(ggplot2)
library(gganimate)
theme_set(theme_bw())
library(gapminder)
head(gapminder)
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 = "GDP per capital", y = "Life expectancy")
p + facet_wrap(~continent) +transition_time(year) +labs(title = "Year: {frame_time}")

让视图跟着每帧数据变

p + transition_time(year) +labs(title = "Year: {frame_time}") +view_follow(fixed_y = TRUE)

Show preceding frames with gradual falloff
This shadow is meant to draw a small wake after data by showing the latest frames up to the current. You can choose to gradually diminish the size and/or opacity of the shadow. The length of the wake is not given in absolute frames as that would make the animation susceptible to changes in the framerate. Instead it is given as a proportion of the total length of the animation.

Show the original data as background marks
This shadow lets you show the raw data behind the current frame. Both past and/or future raw data can be shown and styled as you want.

p + transition_time(year) +labs(title = "Year: {frame_time}") +shadow_wake(wake_length = 0.1, alpha = FALSE)


Reveal data along a given dimension
This transition allows you to let data gradually appear, based on a given time dimension.

Static plot

p + transition_time(year) +labs(title = "Year: {frame_time}") +shadow_mark(alpha = 0.3, size = 0.5)


Let data gradually appear
Reveal by day (x-axis)

library(ggplot2)
library(gganimate)
theme_set(theme_bw())
library(gapminder)
p <- ggplot(airquality,aes(Day, Temp, group = Month, color = factor(Month))
) +geom_line() +scale_color_viridis_d() +labs(x = "Day of Month", y = "Temperature") +theme(legend.position = "top")
p


Show points:

p + transition_reveal(Day)


Points can be kept by giving them a unique group:

p + geom_point() +transition_reveal(Day)


Transition between several distinct stages of the data
Create a bar plot of mean temperature:

p + geom_point(aes(group = seq_along(Day))) +transition_reveal(Day)


transition_states():

library(dplyr)
mean.temp <- airquality %>%group_by(Month) %>%summarise(Temp = mean(Temp))
mean.temp
p <- ggplot(mean.temp, aes(Month, Temp, fill = Temp)) +geom_col() +scale_fill_distiller(palette = "Reds", direction = 1) +theme_minimal() +theme(panel.grid = element_blank(),panel.grid.major.y = element_line(color = "white"),panel.ontop = TRUE)
p

library(dplyr)
mean.temp <- airquality %>%group_by(Month) %>%summarise(Temp = mean(Temp))
mean.temp
p <- ggplot(mean.temp, aes(Month, Temp, fill = Temp)) +geom_col() +scale_fill_distiller(palette = "Reds", direction = 1) +theme_minimal() +theme(panel.grid = element_blank(),panel.grid.major.y = element_line(color = "white"),panel.ontop = TRUE)
p + transition_states(Month, wrap = FALSE) +shadow_mark()

enter_grow() + enter_fade()

p + transition_states(Month, wrap = FALSE) +shadow_mark() +enter_grow() +enter_fade()

参考资料:

https://www.datanovia.com/en/blog/gganimate-how-to-create-plots-with-beautiful-animation-in-r/
https://cloud.tencent.com/developer/article/1675209
TED:https://www.ted.com/talks/hans_rosling_the_best_stats_you_ve_ever_seen?language=zh-TW

GDP与人预期寿命的关系图----R相关推荐

  1. 离散数学【关系】习题解析 序偶,直积,关系图,关系矩阵,哈斯图

    下面是习题与解析 文章目录 第一题 序偶与类型 第二题 关系图,矩阵与类型 第三题关系图,矩阵与类型 第四题 复合关系 第五题 求t( R) 第六题 求表达式 第七题 求关系图等价类 第八题 写出序偶 ...

  2. R语言使用lm函数构建回归模型、使用broom包的augmented函数将模型结果存入dataframe中、使用ggplot2可视化回归残差图(拟合值和残差值的关系图)

    R语言使用lm函数构建回归模型.使用broom包的augmented函数将模型结果存入dataframe中.使用ggplot2可视化回归残差图(拟合值和残差值的关系图) 目录

  3. R语言相关性分析及通过corrplot函数画出一些好看的相关关系图

    数据集 我们以内置的mtcars为例,至于里面的每个变量是啥意思,可以看下面的 (不知道每个变量啥意思也没有关系) [, 1] mpg Miles/(US) gallon [, 2] cyl Numb ...

  4. ICLR 2020 开源论文 | 多关系图神经网络CompGCN

    ©PaperWeekly 原创 · 作者|纪厚业 学校|北京邮电大学博士生 研究方向|图神经网络.推荐系统 图神经网络已经成为图数据分析领域的经典算法了,各大顶会上相关的论文也层出不穷.但是,这些工作 ...

  5. python绘制人际关系图_干货!利用Python绘制精美网络关系图

    Python实战社群 Java实战社群 长按识别下方二维码,按需求添加 扫码关注添加客服 进Python社群▲ 扫码关注添加客服 进Java社群▲ 作者丨tan45du 来源丨袁厨的算法小屋(ID:t ...

  6. 使用pyecharts绘制系统依赖关系图

    使用pyecharts绘制系统依赖关系图 背景介绍 近期梳理了公司内部系统之间的数据关系,得到了多个excel格式的统计文件,每个文件包含了该系统自身数据清单.依赖的其他系统的数据清单.对其他系统供应 ...

  7. python实现对小说的文本分析(人物关系图,人物词云等)

    文本分析 0.效果图 这里有些"二人"."不会"等词语没用筛选掉,手动筛选即可. 1.整体思路: 调用的库:jieba,matplotlib,networkx, ...

  8. python关系图谱_python 绘制三国人物关系图

    author:weizhendong data:2019.12.19 func:绘制三国演义人物关系图 """ import codecs import jieba.po ...

  9. Python 三国演义文本可视化(词云,人物关系图,主要人物出场次数,章回字数)

    文章目录 效果展示 介绍 软件架构 使用说明 导入需要的库 执行main.py 这里以三国演义为例 三国演义.txt alice_mask.png 效果展示 介绍 Python读取小说文本,绘制词云图 ...

最新文章

  1. 逻辑模型三要素-完整性约束
  2. XSS 前端防火墙 —— 无懈可击的钩子
  3. JPA模糊查询(表中的某些数据)
  4. Android中对手机文件进行读写
  5. iphone手机备忘录迁移_如何在iPhone和iPad上使用语音备忘录
  6. 用鼠标去控制物体移动的方法
  7. xp下创建DOMDocument对象失败的解决方法
  8. 系统学习数字图像处理之描绘子
  9. html设置桌面背景win7,win7系统设置默认桌面背景的还原方案
  10. ISO镜像安装WIN10到NVME固态硬盘,无法找到新加装的NVME硬盘(驱动器)
  11. html表格中加入斜线,html中给表格添加斜线
  12. 慕课编译原理(第十章.构造优先关系表)
  13. 谈谈产品与运营之 - 润物细无声
  14. 详解AD(Altium Designer)中的机械层 - 2
  15. docker容器化部署nginx前端项目
  16. 输入年份和天数计算出几月几号
  17. c语言字符图形的操作叙述,C语言课程设计--(图形编程_全).doc
  18. 光谱预处理方法综述及分析策略选择
  19. Mac不能拷贝文件到U盘?看这里就对了!
  20. 如何调整参数来更好地使用频谱分析仪

热门文章

  1. ……微软学生开发者峰会……
  2. 图像增强-直方图均衡化
  3. 一个二维乱序数组,寻找不在数组中的最小自然数(java)。
  4. linux 服务器时间校正
  5. 史上最萌挑战现身海天蚝油《挑战不可能之加油中国》
  6. 河北专接本微机原理错题整理
  7. rtmp服务器初体验
  8. VirtualBox: 开源的Virtual Machine
  9. dip和px相互转换的工具类
  10. Neutron原理详解