由于df$value已经通过round()四舍五入为零位小数,因此可以使用作为角色()设置标签时。
> df$value
[1] 29 81 92 50 43 73 40 41 69 15 11 66 4 69 78
> as.character(df$value)
[1] "29" "81" "92" "50" "43" "73" "40" "41" "69" "15" "11" "66" "4" "69" "78"
ggp <- ggplot(df, aes(x = ordering, y = value)) +
geom_bar(stat = "identity", aes(fill = group)) +
transition_states(year, transition_length = 2, state_length = 0) +
geom_text(label = as.character(df$value))