Recently Published
factor by economic status
# Load necessary libraries
library(ggplot2)
library(plotly)
library(htmlwidgets)
# 1. Create the ggplot object with the boxplot
gg_boxplot <- ggplot(data, aes(x = Economy_status_Developed, y = Life_expectancy)) +
geom_boxplot() +
labs(title = "Boxplot of Life Expectancy by Economy Status",
x = "Economy Status",
y = "Life Expectancy")
# 2. Convert the ggplot object to a Plotly object
p_plotly <- ggplotly(gg_boxplot)
# 3. Display the interactive plot in the RStudio viewer or your web browser
# This will show the plot in your RStudio's viewer pane or default web browser
print(p_plotly)
# 4. Save the Plotly plot as an HTML file
htmlwidgets::saveWidget(p_plotly, "Life_Expectancy_by_Status_Plotly.html")