Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- library(gganimate)
- tbl <- tibble(x = seq(-8, 8, by = .01),
- A_1 = 4*x,
- B_1 = x^2,
- A_2 = 3*x,
- B_2 = x^2,
- A_3 = 2*x,
- B_3 = x^2,
- A_4 = x,
- B_4 = x^2,
- A_5 = 0*x,
- B_5 = x^2) %>%
- gather(group, density, A_1:B_5) %>%
- separate(group, c("group", "type"), sep = "_") %>%
- mutate(type = as.numeric(type)) %>%
- mutate(Title = case_when(
- type == 1 ~ "A = 0, B = 4",
- type == 2 ~ "A = 0, B = 3",
- type == 3 ~ "A = 0, B = 2",
- type == 4 ~ "A = 0, B = 1",
- TRUE ~ "A = B = 0"
- ))
- ggplot(tbl) + geom_line(mapping = aes(x = x, y = density, colour = group)) +
- transition_states(Title, transition_length = .5, state_length = 2, wrap = TRUE) +
- labs(title = '{closest_state}') + ylab("f(x)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement