gpt4 book ai didi

r - 在 R 中使用 gganimate 创建绘图动画的问题

转载 作者:行者123 更新时间:2023-12-04 12:49:18 32 4
gpt4 key购买 nike

我正在尝试使用 gganimate 创建动画

为了制作我想要的动画,我遵循了这个教程: https://github.com/dgrtwo/gganimate 基本上可以满足我的需求。

数据可以在下面找到

这是我的情节的代码

library(ggplot2)
library(gganimate)
install.packages("cowplot")
library(cowplot)

devtools::install_github("dgrtwo/gganimate")

theme_set(theme_bw())
v <- ggplot(Average_position_salary, aes(x = Average_WAR, y = Average_Salary, frame = year)) +
geom_point()

gganimate(v, title_frame = FALSE, interval = 0.1)

问题是当我运行这段代码时,我不断收到这个错误,

Error in check.options(new, name.opt = ".X11.Options", envir = .X11env) : 
invalid argument name ‘interval’ in 'grDevices::png(..., res = dpi, units = "in")'

我不确定我是否理解这个错误,但我尝试删除 interval = 0.1,当我这样做时,我得到了这个错误:

sh: convert: command not found
Error in cmd.fun(sprintf("%s --version", convert), intern = TRUE) :
error in running command
I cannot find ImageMagick with convert = 'convert'
Error in file(file, "rb") : cannot open the connection
In addition: Warning messages:
1: In animation::im.convert(filenames[-1], basename(filename), extra.opts = opts, :
Please install ImageMagick first or put its bin path into the system PATH variable
2: In file(file, "rb") :
cannot open file '/var/folders/ft/7dytfk1d6v50xmp71h6txgrh0000gn/T//RtmpekDeyj/gganimate/file38f501e67b9.gif': No such file or directory

有人知道我做错了什么吗?

谢谢

这是一个数据示例:

    Position year Average_Salary Average_WAR
24 2 1985 508398.2 1.5117647
25 2 1986 375056.4 0.9309091
26 2 1987 369100.2 0.6736842
27 2 1988 350883.5 0.6741935
28 2 1989 395239.8 0.5896552
29 2 1990 369823.7 0.6753623
30 2 1991 524865.5 0.6210526
31 2 1992 726446.3 0.6779661
32 2 1993 693320.1 0.8317460
33 2 1994 731309.5 0.4952381
34 2 1995 657469.8 0.5902778
35 2 1996 739594.1 0.7774194
36 2 1997 886851.8 0.8698413
37 2 1998 961986.3 0.5849315
38 2 1999 1112187.0 0.6171053
39 2 2000 1521829.2 1.0368421
40 2 2001 1794504.4 0.6830508
41 2 2002 2155796.8 0.6537037
42 2 2003 2310309.2 0.9947368
43 2 2004 1777468.4 0.6814815
44 2 2005 2053411.3 0.6758621
45 2 2006 2076933.3 0.7677966
46 2 2007 2148252.9 0.6316667
47 2 2008 2122456.8 0.8619048
48 2 2009 1849889.7 0.7250000
49 2 2010 1959554.4 0.7833333
50 2 2011 1707032.1 0.9651515
51 2 2012 2095852.0 0.9984127
52 2 2013 2285045.4 0.9940299
53 2 2014 2402914.8 1.0936508
54 2 2015 2598519.3 0.6887097
55 3 1985 580910.9 1.2560976
56 3 1986 593094.4 1.1116279
57 3 1987 580782.4 1.6777778
58 3 1988 527230.1 0.9952381
59 3 1989 700261.7 1.3487179
60 3 1990 682741.7 1.0232143
61 3 1991 1131729.7 1.1216216
62 3 1992 1615097.2 1.5416667
63 3 1993 1350687.5 1.4583333
64 3 1994 1443432.7 1.1733333
65 3 1995 2002190.4 1.3914894
66 3 1996 1913476.7 1.4160000
67 3 1997 2739371.2 1.9611111
68 3 1998 2188290.6 1.6437500
69 3 1999 1894013.6 1.4460000
70 3 2000 3058889.0 1.7181818
71 3 2001 3322784.5 1.6097561
72 3 2002 3923671.2 1.6065217
73 3 2003 3947089.0 1.1311111
74 3 2004 4328143.5 1.4369565
75 3 2005 3755095.9 1.4875000
76 3 2006 3048467.7 1.3591837
77 3 2007 3354178.6 0.8843137
78 3 2008 5355219.8 1.3130435
79 3 2009 4264821.3 1.4732143
80 3 2010 5519959.9 1.5813953
81 3 2011 4736312.7 1.4162791
82 3 2012 4738315.8 0.7580000
83 3 2013 4838826.5 1.1980392
84 3 2014 5433374.2 1.1129630
85 3 2015 5965488.6 1.4191489

最佳答案

提供的其他两个答案适用于 Windows,但如果您是 Mac 用户,则可以使用 brew install imagemagick 安装 Image Magick。

在升级到 Sierra/High Sierra 后,我确实遇到了其他问题,因为我无法再写入 /usr/local/Cellar,但能够通过重新安装解决此问题Homebrew (/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)") 然后更新我的权限 sudo chown -R $(whoami) $(brew --prefix)/*.希望这对您有所帮助!

关于r - 在 R 中使用 gganimate 创建绘图动画的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41250947/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com