我处理的财务数据大多是不连续的,这意味着需要从图表中省略收盘时间和周末。 Highcharter似乎很擅长处理这样的数据,但如何将其图表转换为gif?我知道如何使用ggplot和gganimate来做到这一点,但这种组合并不能很好地处理金融数据。 下面是一个简单的折线图(10年期美国国债收益率)在Highcharter中完成,但我想将其动画并将其保存为gif。任何帮助都将不胜感激。 #load packages -------
library(here)
library(tidyverse)
library(highcharter)
# read in data -------
un
我有一个时间序列折线图,其中包含特定日期的注释,我希望仅在动画到达该特定日期时才显示这些注释,并一直显示到动画结束。下面是一个示例-我希望在行达到1945时出现“二战结束”的行和文本: ? library(tidyverse)
library(gganimate)
library(babynames)
# Keep only 1 name
don <- babynames %>%
dplyr::filter(name %in% c("Adolph"))
# Plot
don %>%
ggplot(aes(x = year, y = n
包gganimate创建gifs (来自的MWE代码):
library(ggplot2)
#devtools::install_github('thomasp85/gganimate')
library(gganimate)
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
# Here comes the gganimate code
transition_states(
我正在尝试使用gganimate创建一个动画时间序列情节。下面的代码几乎产生了所需的输出。它创建两个随机时间序列,构造一个数据帧并呈现所需的动画:
# necessary packages
require(ggplot2)
require(gganimate)
require(transformr)
require(gifski)
# construct data frame with two random time series and time index t
TS = matrix(rnorm(100 * 2), 100, 2)
plot.df = data.frame(TS
我有一个问题,动画的情节,在一些层中的数据,目前只在一些框架。在下面的例子中,我有一个移动点,可以沿着9帧很好地动画。但是,当我添加另一个仅在某些帧中存在点的层时,我会得到以下错误:
错误:时间数据必须是所有层中相同的类
示例
require(data.table)
require(ggplot2)
require(gganimate)
# 9 points along x=y; present at every time point
dtP1 = data.table(x = 1:9,
y = 1:9,
t = 1:
我想有2个动画情节,与go同步。因此,也许我有一个包含3列(时间、x和y)的数据集,当我们逐步执行时间时,x的图和y的图同步移动。此外,我希望这是一个R-闪亮的应用程序,有一个按钮,名为'make a step‘,控制动画。我希望使用gganimate,然后我所需要的就是设置当前显示的帧的方法。这有可能吗?
非常感谢,
我第一次尝试使用gganimate包,在处理缺失值(NA)时遇到了一个问题。如果我的问题很琐碎,我很抱歉,但我找不到任何解决方案。
下面是我正在尝试做的一个可重复的例子:
# Load libraries:
library(ggplot2)
library(gganimate)
library(dplyr)
library(tidyr)
# Create some data
## Monthly sales are in 100:1000
## Expected sales are 400/month, increasing by 5% every year
set.seed(1