英文:
How to make the arrows animate in R
问题
如何使箭头从一端移动到另一端。我想表示能量流动。
plot <- ggplot(combined_total_active_2, aes(x = 0, y = 0)) +
coord_fixed() +
theme_void() +
theme(panel.background = element_rect(fill = "#11141a"),
plot.background = element_rect(fill = "#11141a"))
# 添加连接圆圈的线段
plot <- plot +
geom_curve(aes(x = 0, y = 0, xend = -1, yend = 0),
curvature = 0, arrow = arrow(length = unit(0.21, "inches")),
color = "#ffc559", size = 1.2, alpha = 0.6) +
geom_segment(aes(x = -3, y = 0, xend = 3, yend = 0), color = "#ffc559",
size = 1.5, lineend = "round") +
geom_segment(aes(x = 0, y = -3, xend = 0, yend = 3), color = "#ffc559",
size = 1.5, lineend = "round")
plot
英文:
How can I make the arrow move from one end to other. I want to represent an energy flow.
plot <- ggplot(combined_total_active_2, aes(x = 0, y = 0)) +
coord_fixed()+
theme_void()+
theme(panel.background = element_rect(fill = "#11141a"),
plot.background = element_rect(fill = "#11141a"))
# Add lines connecting the circles
plot <- plot +
geom_curve(aes(x = 0, y = 0, xend = -1, yend = 0),
curvature = 0, arrow = arrow(length = unit(0.21, "inches")),
color = "#ffc559", size = 1.2, alpha = 0.6)+
geom_segment(aes(x = -3, y = 0, xend = 3, yend = 0), color = "#ffc559",
size = 1.5, lineend = "round") +
geom_segment(aes(x = 0, y = -3, xend = 0, yend = 3), color = "#ffc559",
size = 1.5, lineend = "round")
plot
答案1
得分: 1
使用gganimate
,您可以执行以下操作:
library(gganimate)
p <- ggplot(data.frame(val = seq(3, -3, -0.1), time = 1:61)) +
geom_segment(arrow = arrow(length = unit(0.21, "inches")),
color = "#ffc559", linewidth = 1.2, alpha = 0.6,
aes(x = 3, y = 0, xend = val, yend = 0)) +
geom_hline(color = "#ffc559", linewidth = 1.2, yintercept = 0) +
geom_vline(color = "#ffc559", linewidth = 1.2, xintercept = 0) +
coord_fixed(xlim = c(-3, 3), ylim = c(-3, 3)) +
theme_void() +
theme(panel.background = element_rect(fill = "#11141a"),
plot.background = element_rect(fill = "#11141a")) +
transition_manual(time)
animate(p, fps = 61)
要更改为填充的圆圈,只需执行以下操作:
p <- ggplot(data.frame(val = seq(3, -3, -0.1), time = 1:61)) +
geom_point(aes(x = val, y = 0), size = 8, color = "#ffc559") +
geom_hline(color = "#ffc559", linewidth = 1.2, yintercept = 0) +
geom_vline(color = "#ffc559", linewidth = 1.2, xintercept = 0) +
coord_fixed(xlim = c(-3, 3), ylim = c(-3, 3)) +
theme_void() +
theme(panel.background = element_rect(fill = "#11141a"),
plot.background = element_rect(fill = "#11141a")) +
transition_manual(time)
animate(p, fps = 61)
您提供的R代码已经被翻译成中文。
英文:
Using gganimate
you could do:
library(gganimate)
p <- ggplot(data.frame(val = seq(3, -3, -0.1), time = 1:61)) +
geom_segment(arrow = arrow(length = unit(0.21, "inches")),
color = "#ffc559", linewidth = 1.2, alpha = 0.6,
aes(x = 3, y = 0, xend = val, yend = 0)) +
geom_hline(color = "#ffc559", linewidth = 1.2, yintercept = 0) +
geom_vline(color = "#ffc559", linewidth = 1.2, xintercept = 0) +
coord_fixed(xlim = c(-3, 3), ylim = c(-3, 3)) +
theme_void() +
theme(panel.background = element_rect(fill = "#11141a"),
plot.background = element_rect(fill = "#11141a")) +
transition_manual(time)
animate(p, fps = 61)
EDIT
To change to a filled circle we can just do
p <- ggplot(data.frame(val = seq(3, -3, -0.1), time = 1:61)) +
geom_point(aes(x = val, y = 0), size = 8, color = "#ffc559") +
geom_hline(color = "#ffc559", linewidth = 1.2, yintercept = 0) +
geom_vline(color = "#ffc559", linewidth = 1.2, xintercept = 0) +
coord_fixed(xlim = c(-3, 3), ylim = c(-3, 3)) +
theme_void() +
theme(panel.background = element_rect(fill = "#11141a"),
plot.background = element_rect(fill = "#11141a")) +
transition_manual(time)
animate(p, fps = 61)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论