R 在 anim_save 中卡在渲染上
R stuck on rendering in anim_save
我尝试 运行 下面这段代码。我 运行 遇到的问题是,如果我不设置宽度和高度,它会保存,如果我设置宽度和高度,它就会卡在 运行ning 中而不会保存(我试着让它 运行 一天)。
我还在多台机器上尝试了代码。
非常感谢您的帮助
## Data generation (This works, but is included to reproduce the exact data)
set.seed(2711)
library('MASS')
library(tidyverse)
library(magrittr)
library(gganimate)
group_loop_df <-
lapply(seq(100, 1000, 100), function(sample_size){
test1 <- data.frame(V1 = truncnorm::rtruncnorm(sample_size, 1, 10, 5, 2))
summary_test <- Rmisc::summarySE(test1, "V1")
test1$ci_V1 <- summary_test$ci
test1$sd_V1 <- summary_test$sd
test1$mean_V1 <- summary_test$V1
hist_data <- ggplot_build(ggplot(test1) +
aes(x = V1) +
geom_histogram() +
theme_classic())$data[[1]]
test1$ceiling_var <- max(hist_data$count)
test1$sample_size <- sample_size
test1$group <- "Group 1"
test2 <- data.frame(V1 = truncnorm::rtruncnorm(sample_size, 1, 10, 4, 2))
summary_test <- Rmisc::summarySE(test2, "V1")
test2$ci_V1 <- summary_test$ci
test2$sd_V1 <- summary_test$sd
test2$mean_V1 <- summary_test$V1
hist_data <- ggplot_build(ggplot(test2) +
aes(x = V1) +
geom_histogram() +
theme_classic())$data[[1]]
test2$ceiling_var <- max(hist_data$count)
test2$sample_size <- sample_size
test2$group <- "Group 2"
overall <- rbind(test1, test2)
overall$p <- t.test(V1 ~ group, overall)$p.value
overall
}) %>%
do.call(rbind, .)
full_hist_overlap <- ggplot(group_loop_df) +
geom_histogram(aes((y=..count../sum(..count..)) * 100, x = V1, fill = group) ) +
geom_vline(aes(xintercept = mean_V1, color = group), size = 2) +
geom_vline(aes(xintercept = mean_V1 - ci_V1, color = group), linetype = "dashed", size = 2) +
geom_vline(aes(xintercept = mean_V1 + ci_V1, color = group), linetype = "dashed", size = 2) +
theme_classic() +
labs(y = "Percent of Values", x = NULL) +
transition_states(sample_size,
transition_length = 5,
state_length = 10) +
ggtitle('Now showing {closest_state} samples') +
ease_aes('cubic-in-out')
### This is where the error occurs.
### This works
anim_save("hist_overlap.gif")
### This does not
anim_save("hist_overlap.gif", units = "cm",
width = 25.4, height = 14.288, res = 300)
这对我有用。我认为解析参数属于 anim_save
调用的 animate
函数,但 anim_save
似乎没有传递这些参数。
animate(full_hist_overlap, units = "cm",
width = 25.4, height = 14.288, res = 300)
anim_save("hist_overlap.gif")
我尝试 运行 下面这段代码。我 运行 遇到的问题是,如果我不设置宽度和高度,它会保存,如果我设置宽度和高度,它就会卡在 运行ning 中而不会保存(我试着让它 运行 一天)。 我还在多台机器上尝试了代码。 非常感谢您的帮助
## Data generation (This works, but is included to reproduce the exact data)
set.seed(2711)
library('MASS')
library(tidyverse)
library(magrittr)
library(gganimate)
group_loop_df <-
lapply(seq(100, 1000, 100), function(sample_size){
test1 <- data.frame(V1 = truncnorm::rtruncnorm(sample_size, 1, 10, 5, 2))
summary_test <- Rmisc::summarySE(test1, "V1")
test1$ci_V1 <- summary_test$ci
test1$sd_V1 <- summary_test$sd
test1$mean_V1 <- summary_test$V1
hist_data <- ggplot_build(ggplot(test1) +
aes(x = V1) +
geom_histogram() +
theme_classic())$data[[1]]
test1$ceiling_var <- max(hist_data$count)
test1$sample_size <- sample_size
test1$group <- "Group 1"
test2 <- data.frame(V1 = truncnorm::rtruncnorm(sample_size, 1, 10, 4, 2))
summary_test <- Rmisc::summarySE(test2, "V1")
test2$ci_V1 <- summary_test$ci
test2$sd_V1 <- summary_test$sd
test2$mean_V1 <- summary_test$V1
hist_data <- ggplot_build(ggplot(test2) +
aes(x = V1) +
geom_histogram() +
theme_classic())$data[[1]]
test2$ceiling_var <- max(hist_data$count)
test2$sample_size <- sample_size
test2$group <- "Group 2"
overall <- rbind(test1, test2)
overall$p <- t.test(V1 ~ group, overall)$p.value
overall
}) %>%
do.call(rbind, .)
full_hist_overlap <- ggplot(group_loop_df) +
geom_histogram(aes((y=..count../sum(..count..)) * 100, x = V1, fill = group) ) +
geom_vline(aes(xintercept = mean_V1, color = group), size = 2) +
geom_vline(aes(xintercept = mean_V1 - ci_V1, color = group), linetype = "dashed", size = 2) +
geom_vline(aes(xintercept = mean_V1 + ci_V1, color = group), linetype = "dashed", size = 2) +
theme_classic() +
labs(y = "Percent of Values", x = NULL) +
transition_states(sample_size,
transition_length = 5,
state_length = 10) +
ggtitle('Now showing {closest_state} samples') +
ease_aes('cubic-in-out')
### This is where the error occurs.
### This works
anim_save("hist_overlap.gif")
### This does not
anim_save("hist_overlap.gif", units = "cm",
width = 25.4, height = 14.288, res = 300)
这对我有用。我认为解析参数属于 anim_save
调用的 animate
函数,但 anim_save
似乎没有传递这些参数。
animate(full_hist_overlap, units = "cm",
width = 25.4, height = 14.288, res = 300)
anim_save("hist_overlap.gif")