R和gganimate:如何更改标题
早上好,社区, 我有以下代码片段:R和gganimate:如何更改标题,r,gganimate,R,Gganimate,早上好,社区, 我有以下代码片段: library( animation ) library( dplyr ) library( gganimate ) library( ggplot2 ) someData = data.frame( years = seq( -5000, 1000, by = 100 ) ) %>% mutate( values = sample( 1:20, length( years ), replace = TRUE ), label =
library( animation )
library( dplyr )
library( gganimate )
library( ggplot2 )
someData = data.frame( years = seq( -5000, 1000, by = 100 ) ) %>%
mutate( values = sample( 1:20, length( years ), replace = TRUE ),
label = ifelse( years < 0, paste0( abs( years ), ' B.C.E.' ), years ) )
chart = ggplot( someData ) +
geom_line( aes( x = years, y = values, frame = years, cumulative = TRUE ) ) +
ggtitle( 'Year: ' )
gganimate( chart, interval = .2 )
但这给了我以下错误:
Error in frame_vec == f : comparison of these types is not implemented
In addition: Warning message:
In FUN(X[[i]], ...) :
Incompatible methods ("Ops.ordered", "Ops.factor") for "=="
任何帮助都将不胜感激,谢谢。关于此功能,实际上还有一个悬而未决的问题,但它尚未合并到原始回购协议中。同时,您可以使用
devtools::install\u github(“ntetor/gganimate”)
安装修改后的软件包,然后您可以执行以下操作:
gg_animate(chart, title_frame = ~ with(someData, label[years == .]))
谢谢@mtoto。不幸的是,你的解决方案对我不起作用。首先,我必须编写类似以下内容:
gg_animate(图表,title_frame=~someData$label[.])
以避免出现以下错误:错误:无法创建帧标题,未找到对象“label”
。然后,它只为第一帧(公元前5000年)放置正确的标签:它保持不变,直到0标签(未显示在标题中),然后显示NA
。ggtitle
和label
说明也存在问题,因为您在框架
值前添加了文本(例如“年:”):它最终会忽略它。上述问题是否与以下警告相关:geom_路径:每组仅包含一个观察值。您是否需要调整群组美学?
?。谢谢你这工作做得很好,谢谢。通过这种方式修改它:title\u frame=~paste0('Year:'),使用(someData,label[years=.])
,可以获得更有意义的标题。
gg_animate(chart, title_frame = ~ with(someData, label[years == .]))