R gganimate注释不处于转换状态的日期变量

R gganimate注释不处于转换状态的日期变量,r,ggplot2,gganimate,ggrepel,R,Ggplot2,Gganimate,Ggrepel,尝试使用ggplot和gganimate创建动画图表,其中x轴(和transition_states值)为数字,但运行日期变量作为注释覆盖在图表上。动画可以工作,但时间序列中的所有日期似乎都是一次性打印的(所有日期都在彼此的顶部),而不是与动画对应。还尝试在geom_点上方保持一致的ggrepel标签。这是一个reprex: library(dplyr) library(lubridate) library(ggrepel) library(ggplot2) library(gganimate)

尝试使用ggplot和gganimate创建动画图表,其中x轴(和transition_states值)为数字,但运行日期变量作为注释覆盖在图表上。动画可以工作,但时间序列中的所有日期似乎都是一次性打印的(所有日期都在彼此的顶部),而不是与动画对应。还尝试在geom_点上方保持一致的ggrepel标签。这是一个reprex:

library(dplyr)
library(lubridate)
library(ggrepel)
library(ggplot2)
library(gganimate)

a0 <- data.frame(dt = seq(ymd('2020-01-01'),ymd('2020-03-31'), by = '1 day'),
                 num = seq(1,91,by=1), val=seq(1,91,by=1), label = rep("x",91))

p <- ggplot(data=a0, aes(x=num, y=val, color=label)) +
  geom_point(size=10) +
  annotate("text",  x = 75, y = 75,
           label = as.Date(a0$dt), size = 10) +
  geom_text_repel(label=a0$label, size=10) +
  scale_x_continuous() +
  theme_minimal() +
  theme(text = element_text(size=30),
        legend.position = "none")

anim <- p + 
  transition_states(num,
                    transition_length = 10,
                    state_length = 1000)

anim
库(dplyr)
图书馆(lubridate)
图书馆(ggrepel)
图书馆(GG2)
库(gganimate)
a0有趣的问题

检查下面的geom_文本行

p <- ggplot(data=a0, aes(x=num, y=val, color=label, group=num)) +
    geom_point(size=10) +
    geom_text(data=a0, aes(x=75, y=75, label=as.Date(a0$dt), size=10)) +
scale_x_continuous() +
theme_minimal() +
theme(text = element_text(size=30),
    legend.position = "none")
p有趣的问题

检查下面的geom_文本行

p <- ggplot(data=a0, aes(x=num, y=val, color=label, group=num)) +
    geom_point(size=10) +
    geom_text(data=a0, aes(x=75, y=75, label=as.Date(a0$dt), size=10)) +
scale_x_continuous() +
theme_minimal() +
theme(text = element_text(size=30),
    legend.position = "none")
p