我想使用gganimate记录测试情况下的进度: 我到现在为止:
library(tidyverse)
library(gganimate)
data <- tribble(~user, ~agree, ~accord, ~messung,
"1", .8, .9, 1,
"2",.7, .8, 1,
"3", .6, .9, 1)
data2 <- tribble(~user, ~agree2, ~accord2, ~messung2,
"1", .4, .7, 2,
"2", .5, .9, 2,
"3", .9, .9, 2)
data%>%
left_join(data2)%>%
mutate(user = as.numeric(user))%>%
ggplot(aes(x = accord, y = agree))+
geom_point(aes(fill = "grey"), color = "grey", size = 2)+
geom_point(aes(x = accord2, y = agree2), color = "green",
size = 2)+
xlim(0,1)+
ylim(0,1)+
geom_segment(aes(x = accord,
y = agree,
xend = accord2,
yend = agree2),
size = 0.5, arrow = arrow(type="closed", length =
unit(.08, "inches"), angle = 30),
color = "grey")+
theme_minimal()+
guides(fill=FALSE, color=FALSE)+
transition_manual(user)
颜色和表示首先是次要的。重要的是要学习如何使一个接一个的点动画,而先前的点又不会消失? 欢迎任何帮助!谢谢
答案 0 :(得分:4)
我无法使其与transition_manual一起使用,但是您可以使用transition_states获得所需的输出。如果不需要过渡,可以将transition_length设置为零。
data%>%
left_join(data2)%>%
mutate(user = as.numeric(user)) %>%
ggplot() +
geom_point(aes(x = accord, y = agree), color = "grey", size = 2, fill = "grey") +
geom_point(aes(x = accord2, y = agree2), color = "green", size = 2)+
xlim(0,1)+ ylim(0,1)+
geom_segment(aes(x = accord, y = agree, xend = accord2, yend = agree2),
size = 0.5, color = "grey",
arrow = arrow(type="closed", length = unit(.08, "inches"), angle = 30))+
theme_minimal() +
# Use zero for "transition_length" to remove animation easing altogether
transition_states(user, transition_length = 1, state_length = 2) +
# shadow_mark(exclude_layer = 3) # This hides the arrow from animating
shadow_mark()
答案 1 :(得分:0)
也许只是创建另一个保存先前观察值的数据框,然后使用geom_point
添加它:
## Your example:
dat <- data %>%
left_join(data2) %>%
mutate(user = as.numeric(user))
ggplot(dat) +
geom_point(aes(x = accord, y = agree)) +
geom_point(aes(x = accord2, y = agree2), color = "green") +
xlim(0, 1) +
ylim(0, 1) +
geom_segment(aes(
x = accord,
y = agree,
xend = accord2,
yend = agree2
)) +
transition_manual(user) -> p
# Now add:
rows <- unlist(sapply(2:nrow(dat), seq))
cols <- grep("agree|accord", names(dat), val = T)
df_points <- dat[rows, cols]
df_points$user <- rep(dat$user[-1], 2:nrow(dat))
p +
geom_point(aes(x = accord, y = agree), df_points) +
geom_point(aes(x = accord2, y = agree2), df_points, color = "green")