标签: gganimate

geom_text 和暂停动画的问题

我正在尝试复制以下代码(thomasp85/gganimate)。我有两个问题:

  1. 我不想显示第一个的标签(变量:partidos)geom_point
  2. 我希望动画结束后,geom_point会显示最后几秒钟的标签(变量:partidos)。

    dput(polls_)
structure(list(week = structure(c(1551571200, 1551571200, 1551571200, 
1551571200, 1551571200, 1550966400, 1550966400, 1550966400, 1550966400, 
1550966400, 1550361600, 1550361600, 1550361600, 1550361600, 1550361600, 
1549756800, 1549756800, 1549756800, 1549756800, 1549756800, 1549152000, 
1549152000, 1549152000, 1549152000, 1549152000, 1548547200, 1548547200, 
1548547200, 1548547200, 1548547200, 1547942400, 1547942400, 1547942400, 
1547942400, 1547942400, 1547337600, 1547337600, 1547337600, 1547337600, 
1547337600, 1546732800, 1546732800, 1546732800, 1546732800, 1546732800, 
1546128000, 1546128000, 1546128000, 1546128000, 1546128000, 1545523200, 
1545523200, 1545523200, 1545523200, 1545523200, 1544918400, 1544918400, 
1544918400, 1544918400, 1544918400, 1544313600, 1544313600, 1544313600, 
1544313600, 1544313600, 1543708800, 1543708800, 1543708800, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gganimate

4
推荐指数
1
解决办法
529
查看次数

如何使用geom_point在gganimate中创建状态之间的平滑过渡?

我正在尝试使用 gganimate 创建动画图。
当我将以下因素 dat$period 传递给 transition_states 时,
我得到 3 个静态图像。我更愿意让这些点在州与州之间“移动”。

这是我的代码:

plot <-
          ggplot(data = dat, aes(x = age, y = value, color = period)) +
          geom_point(size = 3, aes(group = period)) +
          facet_wrap(~group)+
          transition_states(states=period, transition_length = 2, state_length = 1) +
          ease_aes('linear')+
          enter_fade()+
          exit_fade()

plot
Run Code Online (Sandbox Code Playgroud)

这是我的数据:

   record period value age group
1       1  start    45  24     a
2       2  start     6  22     c
3       3  start    23  32     b
4       4  start    67  11     a
5       1 middle …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gganimate

4
推荐指数
1
解决办法
1080
查看次数

ggplot2 错误消息:seq.default(range[1], range[2], length.out = nframes) 中的错误:'from' 必须是一个有限数

我正在尝试制作以下数据的动画气泡图:

Country/Region  1971    1972    1973    1974    1975    1976    1977    1978    1979    1980    1981    1982    1983    1984    1985    1986    1987    1988    1989    1990    1991    1992    1993    1994    1995    1996    1997    1998    1999    2000    2001    2002    2003    2004    2005    2006    2007    2008    2009    2010    GDP per Capita
  Albania        3.9    4.5      3.9     4.2     4.5    4.9     5.2     6.2      7.5    7.6     6.4      6.7     7.3     7.6    7.2     7.2     7.5      7.6    7.2     6.3      4.4     2.8     2.3    2.3     1.9     1.9      1.4    1.7     3.0      3.1     3.3     3.8    4.0     4.3 …
Run Code Online (Sandbox Code Playgroud)

error-handling r ggplot2 r-markdown gganimate

4
推荐指数
1
解决办法
6017
查看次数

为ggplot2图添加图层的过程设置动画

我开始熟悉了gganimate,但我希望进一步扩展我的GIF.

例如,我可以抛出frame一个变量,gganimate但如果我想动画添加全新图层/ geoms /变量的过程怎么办?

这是一个标准的gganimate例子:

library(tidyverse)
library(gganimate)

p <- ggplot(mtcars, aes(x = hp, y = mpg, frame = cyl)) +
    geom_point()

gg_animate(p)
Run Code Online (Sandbox Code Playgroud)

但是如果我想要gif动画怎么办:

# frame 1
ggplot(mtcars, aes(x = hp, y = mpg)) +
    geom_point()

# frame 2
ggplot(mtcars, aes(x = hp, y = mpg)) +
    geom_point(aes(color = factor(cyl)))

# frame 3
ggplot(mtcars, aes(x = hp, y = mpg)) +
    geom_point(aes(color = factor(cyl), size = wt))

# frame 4
ggplot(mtcars, aes(x = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gganimate

3
推荐指数
1
解决办法
794
查看次数

使用ggmap和gganimate创建"天桥"地图动画

我有一个人到达某个地点的数据集,他们待了多久,以及他们的家乡位置.我想创建一个动画图表,将它们"飞"到目的地,并在旅行结束后将它们返回原点.但我不确定这是否可行gganimate.目前我似乎只能做一个"开始"和"结束"框架,虽然有点难以判断它是否没有足够的框架来执行预期的操作.

这就像我到目前为止的情况:

library(dplyr)
library(ggplot2)
library(ggmap)
library(gganimate)

#Coordinates
europecoords <- c(left = -23, bottom = 36, right = 27.87, top = 70.7)
londonareacoords <- c(left = -.7, bottom = 51, right = 0.2, top = 52)
londonpointcoords <- as.data.frame(list(lon = -.14, lat = 51.49))

#Get the map we'll use as the background
europe <- get_stamenmap(europecoords, zoom = 4, maptype = "toner-lite")

#Sample dataset configuration
numberofpoints <- 10
balance <- 0.1

#Set up an example dataset
ids <- seq(1:numberofpoints)
arrivalday …
Run Code Online (Sandbox Code Playgroud)

r ggmap gganimate

3
推荐指数
1
解决办法
1092
查看次数

使用 geom_line 的 ggplot 中的时间序列

我对 gganimate 比较陌生,我正在尝试在 R studio 上创建一个简单的多项式时间序列图。

x <- 1:100

f <- function (x){
  return(-(x)^2)
}

df <- data.frame(x, y= -(x)^2)

ggplot(df, aes(x, y)) + 
   geom_line() + 
   stat_function(fun=f) + 
   transition_states(x, transition_length = 1, state_length = 2 )
Run Code Online (Sandbox Code Playgroud)

我的错误显示:

" Error in transform_path(all_frames, next_state, ease, params$transition_length[i],  : 
  transformr is required to tween paths and lines "
Run Code Online (Sandbox Code Playgroud)

我想知道 transition_state() 中是否缺少某些东西?它作为静态图看起来不错,但我想让它成为一个时间序列图。

感谢任何建议/帮助!谢谢 !

r ggplot2 rstudio polynomials gganimate

3
推荐指数
1
解决办法
1899
查看次数

gganimate 时间序列和两条线图

下面的源代码在这里。我正在尝试用我的数据复制它。我有一个时间序列数据,我在 y 轴上绘制活动和非活动数字。这是我的示例数据结构:

df <- tibble::tribble(
  ~Date, ~active, ~non_active,
      1,                 848,             335,
      2,                 998,             280,
      3,                1096,             308,
      4,                1127,             274,
      5,                1022,             313,
      6,                 973,             351,
      7,                1131,             302,
      8,                1165,             312,
      9,                1159,             293,
     10,                1192,             311,
     11,                1221,             332,
     12,                1075,             369,
     13,                1056,             416,
     14,                1219,             356,
     15,                1240,             363,
     16,                1270,             376,
     17,                1302,             325,
     18,                1292,             346,
     19,                1104,             374,
     20,                1084,             413,
     21,                1257,             350,
     22,                1306,             356,
     23,                1318,             368, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gganimate

3
推荐指数
1
解决办法
2891
查看次数

在 gganimate 中使用 transition_reveal 来累积绘制线条

有没有办法transition_reveal()在 gganimate 中使用一条一条线来绘制线条 - 或者使用其他转换功能的解决方法..

library(tidyverse)
library(gganimate)
set.seed(1)
d <- tibble(x = 1:100, a = cumsum(rnorm(100)), b = cumsum(rnorm(100))) %>%
  pivot_longer(cols = a:b, names_to = "grp", values_to = "y")
d
# # A tibble: 200 x 3
#        x grp        y
#    <int> <chr>  <dbl>
#  1     1 a     -0.626
#  2     1 b     -0.620
#  3     2 a     -0.443
#  4     2 b     -0.578
#  5     3 a     -1.28 
#  6     3 b     -1.49 
#  7     4 …
Run Code Online (Sandbox Code Playgroud)

r gganimate

3
推荐指数
1
解决办法
264
查看次数

使用 gganimate 指向错误方向的箭头

我有简单的情节:

sample_data <-
  data.frame(
    x = 1:100
    , y = 1:100
  )

temp_plot <-
  ggplot(sample_data
         , aes(x = x
               , y = y)) +
  geom_line(
    size = 3
    , arrow = arrow()
    , lineend = "round"
    , linejoin = "round"
  ) +
  theme_minimal()
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

在此输入图像描述

gganimate我想像这样制作它的动画:

temp_animate <-
  temp_plot +
  transition_reveal(x)

anim_save("temp_animate.gif"
          , temp_animate
          , "~/Downloads/"
          , end_pause = 10)
Run Code Online (Sandbox Code Playgroud)

然而,当我这样做时,箭头一直指向错误的方向,直到最后一帧(暂停以表明该方向是正确的)。

在此输入图像描述

我尝试过使用 中的值arrow(包括各种角度,包括负值),但我所做的似乎都没有纠正箭头的方向(它应该沿着每帧中的当前向量指向)。

如何让箭头始终指向正确的方向?(我将其作为问题交叉发布到 github 目录中)。

r gganimate

3
推荐指数
1
解决办法
413
查看次数

使用 current_frame 或 frame_time 时 gganimate 不显示带日期的标题

我正在创建一个动画,gganimate但我需要在标题上显示日期。我的数据dfdput()包含在最后)很小,当我不显示带有日期的标题但我需要包含它时,动画效果很好。这是我使用的代码:

library(tidyverse)
library(ggplot2)
library(gganimate)
#Code for plot
df %>% 
  pivot_longer(-c(Date)) %>%
  ggplot(aes(x=Date,y=value,color=name,
             group=name))+
  geom_point(size=2)+
  geom_line(size=1)+
  scale_y_continuous(labels = scales::comma)+
  geom_segment(aes(xend = Date, yend = value), linetype = 2, colour = 'grey') +
  geom_text(aes(x = Date, label = sprintf("%5.0f", value),group=name), hjust = 0,show.legend = F,fontface='bold',color='black') +
  theme(axis.text.x = element_text(face = 'bold',color='black'),
        axis.text.y = element_text(face = 'bold',color='black'),
        legend.text = element_text(face = 'bold',color='black'),
        axis.title = element_text(face = 'bold',color='black'),
        legend.position = 'bottom',
        legend.title = element_text(face = 'bold',color='black'),
        legend.justification = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gganimate

3
推荐指数
1
解决办法
641
查看次数

标签 统计

gganimate ×10

r ×10

ggplot2 ×7

error-handling ×1

ggmap ×1

polynomials ×1

r-markdown ×1

rstudio ×1