Мне удалось получить это. Я воспроизвел набор данных, дублируя строки предыдущей даты и добавляя к текущей дате и так далее. Так что частоты будут кумулятивными. Я не смог сделать это в R. Однако данные будут выглядеть так:
Data <- structure(list(Date = c("11 Mar'", "11 Mar'", "11 Mar'", "12 Mar'",
"12 Mar'", "12 Mar'", "12 Mar'", "12 Mar'", "12 Mar'", "13 Mar'",
"13 Mar'", "13 Mar'", "13 Mar'", "13 Mar'", "13 Mar'", "13 Mar'",
"13 Mar'", "13 Mar'", "13 Mar'", "13 Mar'", "14 Mar'", "14 Mar'",
"14 Mar'", "14 Mar'", "14 Mar'", "14 Mar'", "14 Mar'", "14 Mar'",
"14 Mar'", "14 Mar'", "14 Mar'", "14 Mar'", "14 Mar'", "14 Mar'"
), Sex = c("Female", "Male", "Male", "Female", "Female", "Female",
"Male", "Male", "Female", "Female", "Female", "Female", "Female",
"Female", "Female", "Male", "Male", "Male", "Male", "Male", "Female",
"Female", "Female", "Female", "Female", "Female", "Female", "Female",
"Male", "Male", "Female", "Male", "Male", "Male"), AgeGroup = c("20-30",
"20-30", "20-30", "10-20", "20-30", "50-60", "20-30", "20-30",
"60-70", "10-20", "20-30", "20-30", "20-30", "50-60", "60-70",
"20-30", "20-30", "60-70", "60-70", "60-70", "10-20", "20-30",
"20-30", "20-30", "50-60", "60-70", "70-80", "70-80", "20-30",
"20-30", "40-50", "60-70", "60-70", "60-70")), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -34L), spec = structure(list(
cols = list(Date = structure(list(), class = c("collector_character",
"collector")), Sex = structure(list(), class = c("collector_character",
"collector")), AgeGroup = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"))
Затем необходимо добавить enter_grow () и exit_fade () с альфа-значением. Убедитесь, что столбцы отображаются в том же порядке категории. Как правило, полоса для значения, доступного вначале, отображается на графике независимо от цвета. При смещении цвет полосы изменяется.
ggplot(Data, aes(x = AgeGroup, fill = Sex, frame = Date)) +
geom_bar(position = position_dodge(preserve = "single")) +
scale_fill_manual(values = c("lightblue", "darkblue"), drop = TRUE) +
xlab("\nAge Group") + ylab("\nIndividuals") +
ggtitle("\nMarch - April 2020") +
scale_y_discrete(limits= c(2,4,6,8)) +
transition_states(Date, transition_length = 4, state_length = 1) + shadow_mark() +
enter_grow() +
exit_fade(alpha = 1)+
labs(title = 'Date: {closest_state}',
subtitle = "Age and Gender distribution",
caption = "data as of 0945 10 Apr 2020")