library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.1
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.3.1
data(mtcars)
p <- ggplot(mtcars, aes(x = mpg, y = hp, color = factor(cyl))) +
geom_point(size = 3) +
scale_color_discrete(name = "Cylinders") +
labs(title = "Miles per Gallon (mpg) vs. Horsepower (hp)",
x = "Miles per Gallon (mpg)",
y = "Horsepower (hp)") +
theme_minimal()
animated_plot <- p + transition_states(cyl, transition_length = 1, state_length = 1) +
enter_fade() +
exit_fade() +
labs(title = "Cylinders: {closest_state}") +
ease_aes('linear')
animated_plot

anim_save("mtcars_animation.gif", animation = animated_plot)
library(ggplot2)
data("USArrests")
View(USArrests)
ggplot(USArrests, aes(x = Murder, y = Assault)) +
geom_point(size = 3) +
labs(title = "USArrests: Murder vs. Assault",
x = "Murder",
y = "Assault") +
theme_minimal()

library(ggplot2)
data("PlantGrowth")
ggplot(PlantGrowth, aes(x = group, y = weight)) +
geom_bar(stat = "summary", fun = "mean", fill = "steelblue") +
labs(title = "Average Plant Weight by Group",
x = "Group",
y = "Weight") +
theme_minimal()
