資料集是
| 年 | ID | 頂部_1 | 頂部_2 | 頂部_3 |
|---|---|---|---|---|
| 1952年 | 25 | 7012 | 6647 | 6419 |
| 1953年 | 28 | 8850 | 7165 | 6470 |
| 1954年 | 31 | 8188 | 7678 | 7246 |
| 1955年 | 34 | 8586 | 8485 | 7525 |
| 1956年 | 37 | 8850 | 8516 | 8163 |
| 1957年 | 40 | 7525 | 6501 | 不適用 |
| 1958年 | 43 | 8188 | 6165 | 不適用 |
| 1959年 | 46 | 6707 | 6187 | 5630 |
我想得到這樣的東西

我不知道該aes()爭論什么
p <- ggplot( data = x , aes(year, y = ?? )
geom_bar( stat = "identity" )
transition_states(year)
labs(title = "abc")
coord_cartesian(ylim = c(5500 , 9000))
xlab("")
ylab("hgt")
animate(p, nframes = 450, fps=16)
uj5u.com熱心網友回復:
首先,您需要使用melt. 之后,您可以設定transition_states顯示不同年份的條形圖。要在標題中顯示年份,您可以使用{next_state}. 您可以使用以下代碼:
library(tidyverse)
library(gganimate)
library(reshape)
df_melted <- melt(df, id = c("ID", "year"))
p <- df_melted %>%
ggplot(aes(x = variable, y = value, fill = variable))
geom_bar(stat = "identity" )
transition_states(
year,
transition_length = 2,
state_length = 1
)
ease_aes('sine-in-out')
labs(title = "Heighest 3 peaks in Year: {next_state}")
xlab("")
ylab("hgt")
p
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/469435.html
上一篇:在R中可能嗎?組合多個文本(a)為組的每個成員和(b)由組
下一篇:沒有資料刮掉w/Rvest包?
