Ошибка в x [seq_len (xlen - n)] - R - отсортированная гистограмма - PullRequest
1 голос
/ 13 марта 2019

Я разработчик таблиц, но я оказался там, где не могу выполнить сортировку анимации баров в этой программе. Прошу прощения, если это будет действительно начинающий вопрос. Я пытаюсь воспроизвести код из этой темы , но получаю ошибку:

Ошибка в x [seq_len (xlen - n)]: объект типа 'замыкание' не является subsettable

Не могли бы вы помочь мне понять, что я делаю неправильно?

library(tidyverse)
library(gganimate)
theme_set(theme_classic())

df <- data.frame(Player = rep(c("Aguero", "Salah", "Aubameyang", "Kane"), 6), 
             Team = rep(c("ManCity", "Liverpool", "Arsenal", "Tottenham"), 6), 
             Gameday = c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6),
             Goals = c(0,1,2,0,1,1,3,1,2,1,3,2,2,2,4,3,3,2,4,5,5,3,5,6),
             stringsAsFactors = F)
gap <- df %>%

# for each player, note his the rank from his previous day
group_by(Player) %>%
arrange(Gameday) %>%
mutate(prev.rank = lag(rank)) %>%
ungroup() %>%

# for every game day,
# sort players by rank & break ties by previous day's rank
group_by(Gameday) %>%
arrange(rank, prev.rank) %>%
mutate(x = seq(1, n())) %>%
ungroup() %>%

ggplot(aes(x = x, y = Goals, fill = Player, color = Player)) +
# geom_tile(aes(y = Goals/2, height = Goals, width = width)) +
geom_col() +
geom_text(aes(y = 0, label = Player), hjust = 1) +
geom_text(aes(label = Value_lbl), hjust = 0) +

# rest of the code below is unchanged from the question
coord_flip(clip = "off", expand = FALSE) +
scale_y_continuous(labels = scales::comma) +
scale_x_reverse() +
guides(color = FALSE, fill = FALSE) +
labs(title = "Gameday {closest_state}", x="", y = "Goals scored") +
theme(plot.title = element_text(hjust = 0, size = 22),
    axis.ticks.y = element_blank(), 
    axis.text.y  = element_blank(),
    plot.margin = margin(1,1,1,4, "cm")) +
transition_states(Gameday, transition_length = 4, state_length = 1) +
ease_aes('cubic-in-out')
...