我尝试将条形文字粘贴到每个水平条上,仅显示最上面的几项,在这里我使用filter和groupby,不确定这是否是一种好方法
DataFrame:
null
我希望这样,但是请允许我过滤每种状态下的前几项
代码:
df <- data.frame(ordering = c(rep(1:3, 2), 3:1, rep(1:3, 2)),
year = factor(sort(rep(2001:2005, 3))),
value = round(runif(15, 0, 100)),
group = rep(letters[1:3], 5))
代码:
ggplot(df, aes(y = ordering, x = value)) +
geom_barh(stat = "identity", aes(fill = group)) +
geom_text(aes(x= value, y = ordering, label = paste(group, " ")),
vjust = 0.3, hjust = 1,color = 'white',size = 11) +
transition_states(year, transition_length = 2, state_length = 0) +
view_follow(fixed_y = TRUE)