library(flexdashboard)
warning=FALSE
message=FALSE
# Load required libraries
library(ggplot2)
library(dplyr)
library(scales)
library(viridis)
## Loading required package: viridisLite
##
## Attaching package: 'viridis'
## The following object is masked from 'package:scales':
##
## viridis_pal
library(plotly)
# Filtering data for Ethiopia
ethiopia_data <- gapminder %>%
filter(country == "Ethiopia")
# Creating an interactive plot for Ethiopia
ethiopia_plot_interactive <- ggplotly(
ggplot(data = ethiopia_data,
aes(x = year, y = lifeExp, color = gdpPercap, size = pop, text = paste("Country: ", country))) +
geom_point() +
scale_size_continuous(labels = comma) +
scale_color_viridis_c(option = "plasma", end = 0.9) +
labs(x = "Year", y = "Life Expectancy",
color = "GDP Per Capita", size = "Population",
title = "Life Expectancy and GDP Per Capita in Ethiopia (All Years)",
subtitle = "Trends Over the Years",
caption = "Source: The Gapminder Project") +
theme_minimal() +
theme(panel.grid.minor = element_blank())
)
ethiopia_plot_interactive
htmlwidgets::saveWidget(ethiopia_plot_interactive, "ethiopia_plot_interactive.html")
# Filtering data for Sudan
sudan_data <- gapminder %>%
filter(country == "Sudan")
# Creating an interactive plot for Sudan
sudan_plot_interactive <- ggplotly(
ggplot(data = sudan_data,
aes(x = year, y = lifeExp, color = gdpPercap, size = pop, text = paste("Country: ", country))) +
geom_point() +
scale_size_continuous(labels = comma) +
scale_color_viridis_c(option = "plasma", end = 0.9) +
labs(x = "Year", y = "Life Expectancy",
color = "GDP Per Capita", size = "Population",
title = "Life Expectancy and GDP Per Capita in Sudan (All Years)",
subtitle = "Trends Over the Years",
caption = "Source: The Gapminder Project") +
theme_minimal() +
theme(panel.grid.minor = element_blank())
)
sudan_plot_interactive
htmlwidgets::saveWidget(sudan_plot_interactive, "sudan_plot.html")
# Filtering data for Eritrea
eritrea_data <- gapminder %>%
filter(country == "Eritrea")
# Creating an interactive plot for Eritrea
eritrea_plot_interactive <- ggplotly(
ggplot(data = eritrea_data,
aes(x = year, y = lifeExp, color = gdpPercap, size = pop, text = paste("Country: ", country))) +
geom_point() +
scale_size_continuous(labels = comma) +
scale_color_viridis_c(option = "plasma", end = 0.9) +
labs(x = "Year", y = "Life Expectancy",
color = "GDP Per Capita", size = "Population",
title = "Life Expectancy and GDP Per Capita in Eritrea (All Years)",
subtitle = "Trends Over the Years",
caption = "Source: The Gapminder Project") +
theme_minimal() +
theme(panel.grid.minor = element_blank())
)
eritrea_plot_interactive
htmlwidgets::saveWidget(eritrea_plot_interactive, "eritrea_plot_interactive.html")