r - 如何使用 R 将 gganimate 图与表(数据框)合并
问题描述
我正在使用gganimate
,我需要在“移动”图附近添加一个表格(数据框)。我不在乎桌子是否是静态的。
我可以在ggplot
使用包中的grid.arrange
命令绘制绘图时做到这一点gridExtra
,但恐怕我不知道在使用gganimate
.
解决方案
绝对可以使用geom_table
from ggpmisc
。
代码
g <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
geom_point() +
scale_x_log10() +
annotate(geom = "table", x = Inf, y = -Inf,
label = list(mytable),
vjust = 0, hjust = 1) +
transition_time(year) +
labs(title = "Year: {frame_time}")
animate(g)
数据
library(gapminder)
library(ggplot2)
library(gganimate)
library(ggpmisc)
# Transform to numeric to prevent an integer overflow
gapminder$pop <- as.numeric(gapminder$pop)
# Create table
mytable <- gapminder %>%
filter(year == 2007) %>%
group_by(continent = continent) %>%
summarise(pop_mn_2007 = round(sum(pop)/1000000, 1),
avg_lifeExp_2007 = round(mean(lifeExp), 2))
推荐阅读
- java - 当我运行我的项目时出现 NullPointerException
- django - 如何在我的 url 创建错误的开头修复此前缀 www?
- powerbi - 上一次过滤器的总和
- amazon-redshift - Datagrip 中的 DESCRIBE 表等价物?
- python - 根据一列中的多个条件创建新列
- .net-core - 有没有办法监视所有来自 IIS 中托管的 .net 核心应用程序的 http 请求
- vue.js - 构建一个 Vue 库以在非 Vue 应用程序中运行
- android - Android BluetoothLeScanner startScan PendingIntent 在 28 次后系统范围内失败
- asp.net-core - 将 Web Api 授权添加到现有 Razor 页面应用程序
- javascript - React:如何分离管理仪表板和主站点?