#This Climate Dashboard uses climate data from the National Centers for Environmental Information to explore the impact of climate change. The data includes monthly average maximum and minimum temperatures, as well as total precipitation from January 1950 to December 2020. The dashboard visualizes the data using a combination of scatterplots, bar charts, line charts, and boxplots, providing insights into how climate change is affecting different regions and countries. The charts cover a range of variables, including life expectancy, GDP per capita, population, and continent. The visualizations in this dashboard are intended to help us better understand the effects of climate change and take steps towards mitigating its impact.
---
title: "Climate Dashboard"
author: "Your Name"
date: "2023-04-11"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
# Load necessary packages
library(flexdashboard)
library(tidyverse)
library(lubridate)
library(plotly)
# Load and preprocess data
download.file("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv",
destfile = "data.csv", method = "curl")
# Load and preprocess data
climate_data <- read.csv("data.csv", stringsAsFactors = FALSE)
# Rename columns to match dataset from URL
colnames(climate_data) <- c("country", "continent", "year", "lifeExp", "pop", "gdpPercap")
climate_data$year <- as.Date(paste(climate_data$year, "-01-01"), format = "%Y-%m-%d")
climate_data$lifeExp <- as.numeric(climate_data$lifeExp)
climate_data$pop <- as.numeric(climate_data$pop)
climate_data$gdpPercap <- as.numeric(climate_data$gdpPercap)
# Calculate yearly averages
climate_yearly <- climate_data %>%
group_by(year) %>%
summarize(lifeExp = mean(lifeExp), pop = sum(pop), gdpPercap = mean(gdpPercap)) %>%
mutate(year = as.Date(paste(year, "-01-01"), format = "%Y-%m-%d"))
# Calculate yearly percentage changes
climate_yearly_pct <- climate_yearly %>%
mutate(lifeExp_pct = (lifeExp - lag(lifeExp)) / lag(lifeExp) * 100,
pop_pct = (pop - lag(pop)) / lag(pop) * 100,
gdpPercap_pct = (gdpPercap - lag(gdpPercap)) / lag(gdpPercap) * 100)
# Calculate moving averages
climate_ma <- climate_data %>%
group_by(country) %>%
arrange(country, year) %>%
mutate(lifeExp_ma = zoo::rollmean(lifeExp, k = 5, fill = NA, align = "right"),
pop_ma = zoo::rollmean(pop, k = 5, fill = NA, align = "right"),
gdpPercap_ma = zoo::rollmean(gdpPercap, k = 5, fill = NA, align = "right")) %>%
ungroup()
```
Column {data-width=500}
-----------------------------------------------------------------------
### Introduction
#This Climate Dashboard uses climate data from the National Centers for Environmental Information to explore the impact of climate change. The data includes monthly average maximum and minimum temperatures, as well as total precipitation from January 1950 to December 2020. The dashboard visualizes the data using a combination of scatterplots, bar charts, line charts, and boxplots, providing insights into how climate change is affecting different regions and countries. The charts cover a range of variables, including life expectancy, GDP per capita, population, and continent. The visualizations in this dashboard are intended to help us better understand the effects of climate change and take steps towards mitigating its impact.
### Chart A
```{r}
# Create a scatterplot of life expectancy vs. GDP per capita, with country as color
gapminder_data <- read.csv("data.csv", stringsAsFactors = FALSE)
plot1 <- gapminder_data %>%
filter(year == 2007) %>%
ggplot(aes(x = gdpPercap, y = lifeExp, color = country)) +
geom_point() +
scale_x_log10() +
labs(title = "Life Expectancy vs. GDP per Capita (2007)",
x = "GDP per Capita (log scale)",
y = "Life Expectancy",
color = "Country")
# Print the plot
plot1
```
Column {data-width=500}
-----------------------------------------------------------------------
### Chart B
```{r}
# Create a bar chart of mean population by continent
plot2 <- gapminder_data %>%
group_by(continent) %>%
summarize(mean_pop = mean(pop)) %>%
ggplot(aes(x = continent, y = mean_pop, fill = continent)) +
geom_bar(stat = "identity") +
labs(title = "Mean Population by Continent",
x = "Continent",
y = "Mean Population",
fill = "Continent")
# Print the plot
plot2
```
### Chart C
```{r}
# Create a line chart of GDP per capita over time, with one line for each continent
plot3 <- gapminder_data %>%
ggplot(aes(x = year, y = gdpPercap, color = continent)) +
geom_line() +
scale_y_log10() +
labs(title = "GDP per Capita over Time by Continent",
x = "Year",
y = "GDP per Capita (log scale)",
color = "Continent")
# Print the plot
plot3
```
Column {data-width=500}
-----------------------------------------------------------------------
### Chart D
```{r}
# Create a scatterplot of life expectancy vs. GDP per capita, with continent as color
plot4 <- gapminder_data %>%
ggplot(aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point() +
scale_x_log10() +
labs(title = "Life Expectancy vs. GDP per Capita by Continent",
x = "GDP per Capita (log scale)",
y = "Life Expectancy",
color = "Continent")
# Print the plot
plot4
```
### Chart E
```{r}
# Create a boxplot of life expectancy by continent
plot5 <- gapminder_data %>%
ggplot(aes(x = continent, y = lifeExp, fill = continent)) +
geom_boxplot() +
labs(title = "Life Expectancy by Continent",
x = "Continent",
y = "Life Expectancy",
fill = "Continent")
# Print the plot
plot5
```