geom_text()函式在ganimate中沒有正常出現。ganimate正確地列印了線圖的標簽,但沒有為圖表列印。我怎樣才能解決這個問題呢,請問?是否有其他方法可以用ganimate在我的圖上列印數值?
library(tidyr)
library(dplyr)
library(ggplot2)
library(gganimate)
tramway_df <- data.frame()
stop_order = c(1。 2, 3。 4, 5。 6, 7, 8。 9, 10, 11。 12, 13。 14, 15。 16, 17),
stop_id = c(9943。 5041, 5361, 2902。 2903, 5872, 5802。 5803, 5804。 5805, 5805,
5710, 5711。 5712, 1643。 5714, 521。 529),
stop_name = c("DA VINCI"/span>。 "DA VINCI"。 "BORDET STATION", "VAN CUTSEM"。 "FONSON", "PAIX","TILLEUL", "HELMET", "FOYER SCHAERBEEK. ", "WAELHEM"。 "VERBOEKHOVEN", "PAVILLON","RUBENS", "LIEDTS", "THOMAS"。 "GARE DU NORD", "ROGIER"),
stop_in = c(27。 102, 153。 141, 190。 317, 379, 438。 328, 214。 278, 298, 154, 144,/span> 162, 185, 0),
stop_out = c(0。 7, 3。 10, 22, 37。 81, 122。 143,/span> 168。 291, 230, 149。 301,/span> 412。 707, 821),
stop_charge = c(27。 121, 271。 402, 571, 851。 1149, 1465。 1650, 1696。 1682, 1745, 1750。 1592, 1342。 821, 0)
)
plot <- tramway_df %>%
gather(movement, value, stop_in: stop_out) %>%
mutate(stop_id = factor(stop_id, 水平=唯一(stop_id)),>
值 = ifelse(movement == "stop_out"。 -value, value) %> %
ggplot(aes(x =) operator">=stop_id))
geom_col(aes(y = value, 填充=運動)。 位置= "dodge"。 寬度= 1)
geom_point(aes(y =stop_charge)。 color = "green")
geom_line(aes(y = stop_charge, 組=1)。 color = "green")
geom_text(aes(label = value, y = value)。 hjust = 1。 vjust = 0)
geom_text(aes(label = stop_charge。 y = stop_charge)。 hjust = 1。 vjust = 1)
scale_x_discrete(breakaks = tramway_df$stop_id,
標簽 = tramway_df$stop_name)
theme_bw()
主題(axis.text。 x = element_text(angle = 60。 hjust = 1, vjust = 1))
影片<-情節 transition_reveal(stop_order)
animate(animation, height = 500。 寬度 = 800)
uj5u.com熱心網友回復:
通過添加position = position_dodge2(width = 0.9, preserve = "single")和一些引數,它可以正確列印出來。你可能需要更多的引數來定位柱狀圖的文本。
plot <- tramway_df %>%
gather(movement, value, stop_in: stop_out) %>%
mutate(stop_id = factor(stop_id, 水平=唯一(stop_id)),>
值 = ifelse(movement == "stop_out"。 -value, value) %> %
ggplot(aes(x =) operator">=stop_id))
geom_col(aes(y = value, 填充=運動)。 位置= "dodge"。 寬度= 1)
geom_point(aes(y =stop_charge)。 color = "green")
geom_line(aes(y = stop_charge, 組=1)。 color = "green")
geom_text(position = position_dodge2(width = 0。 9,保留= "single")。 aes(label = value。 y =值 30 * sign(value)。 填充=運動, hjust = 0. 5))
geom_text(aes(label = stop_charge, y = stop_charge)。 hjust = 1。 vjust = 1)
scale_x_discrete(breakaks =tramway_df$stop_id,
標簽 = tramway_df$stop_name)
theme_bw()
主題(axis.text。 x = element_text(angle = 60。 hjust = 1, vjust = 1))
影片<-情節 transition_reveal(stop_order)
animate(animation, height = 500。 寬度 = 800)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/318928.html
標籤:

