- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有如下地理数据(但数据量大得多):
library(tidyverse)
library(gganimate)
n <- 500
longitude <- runif(n)
latitude <- runif(n)
time <- round(runif(n, 0, 100),1) %>% sort
data <- tibble(longitude,latitude) %>% arrange(longitude) %>% mutate(time = time)
我可以用 gganimate 制作动画如下:
anim1 <- ggplot(data, aes(x=longitude, y=latitude, group = time)) +
geom_point(color = "red", size = 10) +
transition_components(time, exit_length = 30) +
exit_fade() +
shadow_mark(color = "red" ,alpha = 0.1, size = 10)
animate(anim1, nframes = 100)
这给出了以下输出:
在这里,我同时使用 exit_fade
来使点淡出,还使用 shadow_mark
和设置的 alpha 来使数据持续存在。这基本上非常非常接近我想要的。
问题在于,这里真正发生的是 gganimate 在数据点首次出现在 geom_point 下方后立即放置一个 shadow_mark
,然后在原始点消失时它慢慢变得可见。如果我只是想让点淡出但持续存在,这基本上是可以的(尽管淡入淡出过渡有点奇怪,因为原始的 alpha 和 shadow_mark
在淡出过程中在视觉上加在一起)。但它变成了一个更大的问题,因为有时我还需要调整点的大小。
如果我使用一个小于原始点的shadow_mark
,你可以看到问题:
anim2 <- ggplot(data, aes(x=longitude, y=latitude, group = time)) +
geom_point(color = "red", size = 10) +
transition_components(time, exit_length = 30) +
exit_fade() +
shadow_mark(color = "red" ,alpha = 0.1, size = 2)
animate(anim2, nframes = 100)
给出以下内容:
您可以看到较小的点出现而较大的点逐渐消失(这里为了简单起见我省略了同时调整大小,但在这种情况下问题仍然存在)。所以我想知道是否有一种方法可以在 gganimate 中“正确地”执行此操作,使得该点实际上只是消失但仍然存在,而 shadow_mark
只是在下面绘制并通过逐渐消失慢慢显露出来原点?
问题的原因是我最终想同时平滑exit_fade
和exit_shrink
,这样收缩后的最终大小与上例中的 shadow_mark
尺寸较小,然后该点在整个动画的其余部分一直保持较小的半淡化状态。
注意:我意识到我可以uncount
数据行并在数据中手动制作我自己的帧和转换,并允许点以这种方式持续存在,就像在其他讨论中answers .问题是我的真实数据集实际上非常大,像这样进行计数会导致数据集对于内存来说太大了。因此,如果存在的话,我更喜欢纯 gganimate 解决方案。
最佳答案
以下方法将数据集复制了两次,这确实会导致文件大小稍微膨胀,但可能不会像不计算那样出现问题。看看它是否适合您?
data <- data %>%
mutate(id = seq(1, n()), # add an ID column to original dataset,
type = "original",
size = 10, # specify initial size / alpha / any other aspect
alpha = 1) # to be changed during animation
rbind(data,
data %>% # create second version of the dataset,
mutate(type = "transiting", # with time lagged by the desired transition
time = time + 30, # amount (30 in the question's example),
size = size * 0.2, # & size / alpha / any other aspect defined
alpha = alpha * 0.1), # according to end state after transition;
data %>% # create third version of the dataset,
mutate(type = "persisting", # which should be identical to the second,
time = max(time) + 30, # except that the time is set to the max time
size = size * 0.2, # across all rows.
alpha = alpha * 0.1)) %>%
# pass this combined dataset to ggplot & animate as per normal with explicitly
# specified parameters for size / alpha / etc, & group aesthetic set to ID value.
# no need to specify exit_fade or shadow_mark now, as each point DOESN'T exit at all.
ggplot(aes(x = longitude, y = latitude, group = id,
size = size, alpha = alpha)) +
geom_point(colour = "red") +
transition_components(time) +
ggtitle("{frame_time}") + # optional; added to illustrate frame time explicitly
scale_size_identity() +
scale_alpha_identity()
关于r - 有没有办法让 geoms 褪色但坚持 gganimate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63913059/
有没有办法将使用 ffmmeg_renderer 或 av_renderer 制作的电影保存为单独的文件?我总是将主题作为数据嵌入到 html 文件中。 最佳答案 使用来自@Roman 的示例,我将使
我有以下数据框: # Seed RNG set.seed(33550336) # Create data frame df 将显示一个整数。如果frame_time是一个常规变量,那么使用bquot
几天来我一直在努力解决这个问题,但我不明白我错过了什么。 gganimate 似乎没有在帧之间添加任何过渡。 我正在使用 Tour de France dataset from the tidytue
是否可以在一个动画循环后停止? 动画应执行到去年 2021 年,然后停止显示所有条形图! 这是一个使用 gganimate 的条形动画示例: library(tidyverse) library(gg
我想将我的数据的另一列值插入gganimate动画标题中。 例如,这里的状态级别变量是x,我想添加到标题变量y: df 1 1 a 2 2 a 3 3 b
我有以下生成静态图表的 R 脚本 library(ggplot2) library(dplyr) library(tidyr) library(stringr) library(gta
是否可以在 gganimate 循环之间添加暂停?我知道我们可以使用 interval 设置帧之间的间隔,但是有没有办法在循环回第一帧之前在最后一帧暂停? 将最终帧的多个副本插入到数据中的最佳方法是吗
我正在尝试使用 gganimate 绘制一段时间内 NHL 前 3 名得分手的图。目前,我有一个柱形图,其中 x 轴显示球员姓名,y 轴显示每个球员的进球数。这是我所拥有的静态版本: library(
我有一个如下所示的数据框: head(newnolarank) lon lat week b 1 -90.06445 29.97121 1 9 2 -90.06704 29.9
遵循源代码 Here 。我正在尝试用我的数据复制它。我有一个时间序列数据,我在 y 轴上绘制事件和非事件数字。这是我的示例数据结构: df <- tibble::tribble( ~Date, ~
我已经解析了电子游戏《反恐精英》中手榴弹 throw 的一些数据。下面的示例数据显示我有关于手榴弹从哪里 throw 、手榴弹爆炸的位置以及何时 throw 手榴弹的位置。 df % # Add
我正在尝试使用 gganimate 绘制一段时间内 NHL 前 3 名得分手的图。目前,我有一个柱形图,其中 x 轴显示球员姓名,y 轴显示每个球员的进球数。这是我所拥有的静态版本: library(
我第一次尝试 gganimate 包,但在处理缺失值 (NA) 时遇到了问题。如果我的问题很微不足道,但我找不到任何解决方案,我深表歉意。 这是我正在尝试做的事情的可重现示例: # Load libr
我正在使用 gganimate。假设我有这个 MWE: library(ggplot2) library(gganimate) ggplot(airquality, aes(Day, Temp)) +
使用 gganimate 从 ggplot 制作动画时,我需要设置较低的速度以允许人们读取数据。 阅读文档(很难找到选项)似乎“nframes”是正确的设置。但我不能减慢动画或设置持续时间。两种方法中
以下两行代码,取自 script ,做我认为他们应该做的;也就是使用之前生成的ggplot文件——gganim——在Rstudio的查看器(第一行)中创建一个动画,并将最后一个动画保存到我mac上的g
我正在尝试显示随着时间的推移构建的直方图。它将从 1952 年的数据开始,然后每年更新直方图,并不断增长。 路径似乎是 gganimate,我认为使用 transition_reveal随着时间的推移
我在设置动画时无法设置绘图的宽度。 因此,如果我使用库 gapminder 制作静态图,代码如下: library(ggplot2) library(gganimate) theme_set(them
我想将绘图标签(标题、副标题)对齐到图像的左侧,而不是绘图区域的左侧,以获得 gganimate 动画。 这可以通过转换为 gtable 然后修改布局来使用静态图表。动画需要一种不同的方法,因为 gg
试图创建一个具有简单特征的动画,本质上是一个区域分布图形式的空间变量的时间序列。 问题是多边形在动画播放时遍布整个情节。 这是一个可重现的示例,部分摘自 https://www.blog.cultur
我是一名优秀的程序员,十分优秀!