---
title: "Data in Motion"
subtitle: "Interactive Charts, Maps, and Animations"
author: "Emrah Akbas"
date: today
format:
html:
theme: cosmo
toc: true
toc-depth: 3
toc-title: "Table of Contents"
code-fold: true
code-tools: true
code-link: true
embed-resources: true
grid:
sidebar-width: 250px
body-width: 850px
margin-width: 250px
execute:
echo: false
warning: false
message: false
---
## Dynamic Bubble Chart
This dynamic bubble chart tracks the relationship between national wealth (GDP per capita) and life expectancy across five continents from 1952 to 2007 using the gapminder dataset. Individual bubble sizes scale proportionally to each country's population.
```{r}
#| label = "setup",
#| include = FALSE
pacman::p_load(plotly, tidyverse, gapminder, here, RColorBrewer, scales, highcharter)
```
```{r}
data(gapminder, package = "gapminder")
```
```{r, warning=FALSE}
gg = ggplot(gapminder,
aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point(aes(
size = pop,
frame = year,
ids = country,
text = paste0(
"Country: ", country, "<br>",
"Continent: ", continent, "<br>",
"GDP per Capita: $", scales::comma(gdpPercap, accuracy = 1), "<br>",
"Life Expectancy: ", round(lifeExp, 1), " years<br>",
"Population: ", scales::comma(pop)
)
)) +
scale_x_log10(labels = scales::label_dollar()) +
labs(title = "Global Life Expectancy vs. GDP per Capital Over Time",
x = 'GDP per Capital',
y = 'Life Expectancy',
color = 'Continent') +
scale_color_manual(values = RColorBrewer::brewer.pal(n = 5, name = "Set1")) +
theme_minimal()
```
```{r}
suppressWarnings(ggplotly(gg, tooltip = "text"))
```
## Choropleth Map
```{r}
data(unemployment)
```
This county-level choropleth map highlights employment trends across the United States by showing local unemployment rates. By shading each county based on its jobless rate, the map makes it easy to spot regional economic patterns at a glance. You can quickly see which areas are thriving with high employment and which parts of the country are facing tougher economic challenges.
```{r}
hcmap(map = "countries/us/us-all-all",
data = unemployment,
name = "Unemployment",
value = "value",
joinBy = c("hc-key", "code"),
borderColor = "transparent") |>
hc_colorAxis(dataClasses = color_classes(breaks = c(seq(0, 10, by = 2), 50),
colors = rev(viridisLite::viridis(6)))) |>
hc_legend(layout = "vertical", align = "right",
floating = TRUE, valueDecimals = 0, valueSuffix = "%") |>
hc_title(
text = "United States Unemployment Rates by County",
align = "center",
style = list(fontSize = "20px", fontWeight = "bold", color = "#333333")
)
```
## Multi-Series Line Chart
This line graph displays the seasonal temperature trends across 12 months for four major global cities: Berlin, London, New York City, and Tokyo.
```{r}
data(citytemp)
```
```{r}
citytemp |>
pivot_longer(cols = where(is.numeric), names_to = "city", values_to = "temperature") |>
hchart(type = "line",
hcaes(x = month, y = temperature, group = city)) |>
hc_title(
text = "Average Monthly Temperatures by City",
align = "center",
style = list(fontSize = "20px", fontWeight = "bold")
) |>
hc_xAxis(
labels = list(style = list(fontSize = "14px", color = "#333333"))
) |>
hc_yAxis(
title = list(text = "Temperature", style = list(fontSize = "14px")),
labels = list(style = list(fontSize = "14px", color = "#333333"))
)
```