knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE, dev = "ragg_png")
# Load required libraries
library(ggplot2)
library(gapminder)
library(dplyr)
library(plotly)
library(gganimate)
library(gifski)
library(transformr)
library(htmlwidgets)
library(ragg)
# Create basic scatter plot
library(ggplot2)
library(gapminder)
p <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point(alpha = 0.3, size = 1) +
scale_x_log10() +
geom_smooth(method = "lm", se = FALSE, color = "black") +
labs(title = "Life Expectancy vs GDP per Capita",
subtitle = "Colored by Continent",
x = "GDP per Capita (Log scale)",
y = "Life Expectancy") +
theme_minimal()
# Show plot
p

p_facet <- p + facet_wrap(~ continent) +
labs(title = "Life Expectancy vs GDP per Capita by Continent")
# Show plot
p_facet

library(plotly)
library(htmlwidgets)
interactive_plot <- ggplotly(p)
# Save interactive plot
saveWidget(interactive_plot, "interactive_gapminder_plot.html", selfcontained = TRUE)
print(interactive_plot)
knitr::include_graphics("interactive_gapminder_plot.html")
