【问题标题】:Getting attempt to apply non-function when view_follow() is used in ggplot2在 ggplot2 中使用 view_follow() 时尝试应用非函数
【发布时间】:2020-04-25 18:31:58
【问题描述】:

使用 view_follow() 时“尝试应用非函数”。删除 view_follow() 函数后,它按预期工作。我添加这个来调整轴上绘制的值的 y 轴基础。感谢您的帮助。

可重现的代码如下:

library(plyr)
library(dplyr)
library(ggplot2)
library(reshape)
library(reshape2)
library(gganimate)

samplelData <-
    rbind(
            cbind.data.frame(
                    year = as.integer(seq(from=2001,to=2020,by=1)),
                    Country = c('A'),
                    value = c(1:20)
            ),
            cbind.data.frame(
                    year = as.integer(seq(from=2001,to=2020,by=1)),
                    Country = c('B'),
                    value = seq(from=10,to=400,by=20)
            ))

ggplot(samplelData,
                   aes(
                           x = Country,
                           y = value,
                           fill = Country,
                           frame = year
                   )) + geom_point(stat = 'identity', position = 'dodge') +
            transition_reveal(year) + view_follow(fixed_x = TRUE) + labs(title = "Year: {round(frame_along, 0)}")

【问题讨论】:

    标签: r ggplot2 gganimate


    【解决方案1】:

    以下代码有效: 找到解决方案@https://github.com/thomasp85/gganimate/issues/304

    ggplot(samplelData,
       aes(
               x = as.numeric(as.factor(Country)),
               y = value,
               fill = Country,
               frame = year
       )) + geom_bar(stat = 'identity', position = 'dodge') + scale_x_continuous(breaks = 1:2, labels = unique(samplelData$Country)) +
        transition_reveal(year) + view_follow(fixed_x = T, fixed_y = F) + labs(title = "Year: {round(frame_along, 0)}")
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2018-12-27
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 2021-03-17
      • 2014-09-11
      • 1970-01-01
      • 2019-02-03
      • 1970-01-01
      相关资源
      最近更新 更多