使用 gganimate 时小提琴图的定位
Positioning of violin plots when using gganimate
我正在使用 ggplot2 3.0.0 和 gganimate 0.1.1。
这是一个 MWE:
library(ggplot2)
library(gganimate)
df <- data.frame(year = rep(2000:2010, each = 50),
value = rnorm(550))
ggplot(df, aes(x = 0, y = value, frame = factor(year))) +
geom_violin() -> p
gganimate(p)
这会创建一个动画,其中每一帧看起来都像这样
而我希望每一帧都像这样占据整个情节
我怎样才能调整我的代码来获得这个结果?
编辑
This是我想制作的,这次用的是实际数据。我通过手动将每一帧动画拼接在一起来实现这一点,但这种方式对于更复杂的情节来说是不可持续的,所以我希望改用 gganimate。
只需使用 transition_states()
或 transition_time()
。
代码
ggplot(df, aes(x = 0, y = value)) +
geom_violin() +
transition_states(year, transition_length = 3, state_length = 1) +
labs(title = "{closest_state}")
数据
set.seed(1701)
df <- data.frame(year = c(rep(2000:2010, each = 50)),
value = rnorm(550))
我正在使用 ggplot2 3.0.0 和 gganimate 0.1.1。 这是一个 MWE:
library(ggplot2)
library(gganimate)
df <- data.frame(year = rep(2000:2010, each = 50),
value = rnorm(550))
ggplot(df, aes(x = 0, y = value, frame = factor(year))) +
geom_violin() -> p
gganimate(p)
这会创建一个动画,其中每一帧看起来都像这样
而我希望每一帧都像这样占据整个情节
我怎样才能调整我的代码来获得这个结果?
编辑
This是我想制作的,这次用的是实际数据。我通过手动将每一帧动画拼接在一起来实现这一点,但这种方式对于更复杂的情节来说是不可持续的,所以我希望改用 gganimate。
只需使用 transition_states()
或 transition_time()
。
代码
ggplot(df, aes(x = 0, y = value)) +
geom_violin() +
transition_states(year, transition_length = 3, state_length = 1) +
labs(title = "{closest_state}")
数据
set.seed(1701)
df <- data.frame(year = c(rep(2000:2010, each = 50)),
value = rnorm(550))