Column

Scatterplot — GDP per Kapita vs Harapan Hidup

Line Plot — Tren Harapan Hidup di Indonesia

Box Plot — Distribusi Harapan Hidup per Benua

Bar Plot — Rata-rata Harapan Hidup per Benua

Density Plot — Sebaran Harapan Hidup per Benua

---
title: "Dashboard Gapminder"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    theme: readable
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(gapminder)
library(tidyverse)
library(RColorBrewer)
library(plotly)
library(DT)
library(htmltools)
```

Column {data-width=650}
-----------------------------------------------------------------------

```{r}

datatable(
gapminder,
extensions = 'Scroller',
options = list(
deferRender = TRUE,
scrollY = 400,
scrollX = TRUE,
scroller = TRUE,
pageLength = 10
),
class = 'display nowrap compact',
rownames = FALSE
)

```

## Scatterplot — GDP per Kapita vs Harapan Hidup
```{r}
p1 <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point(alpha = 0.7, size = 2) +
scale_x_log10() +
scale_color_brewer(palette = "Pastel1") +
labs(
title = "Hubungan GDP per Kapita dan Harapan Hidup (1952–2007)",
x = "GDP per Kapita (log scale)",
y = "Harapan Hidup"
) +
theme_minimal(base_size = 14)

htmltools::div(
style = "width: 100vw; height: 100vh; overflow: auto;",
ggplotly(p1)
)
```

## Line Plot — Tren Harapan Hidup di Indonesia
```{r}
p2 <- gapminder %>%
filter(country == "Indonesia") %>%
ggplot(aes(x = year, y = lifeExp)) +
geom_line(color = "#FBB4AE", size = 1.2) +
geom_point(color = "#B3CDE3", size = 3) +
labs(
title = "Tren Harapan Hidup di Indonesia (1952–2007)",
x = "Tahun",
y = "Harapan Hidup"
) +
theme_light(base_size = 14)

htmltools::div(
style = "width: 100vw; height: 100vh; overflow: auto;",
ggplotly(p2)
)
```

## Box Plot — Distribusi Harapan Hidup per Benua
```{r}
p3 <- ggplot(gapminder, aes(x = continent, y = lifeExp, fill = continent)) +
geom_boxplot(alpha = 0.8) +
scale_fill_brewer(palette = "Pastel2") +
labs(
title = "Distribusi Harapan Hidup Berdasarkan Benua",
x = "Benua",
y = "Harapan Hidup"
) +
theme_classic(base_size = 14)

htmltools::div(
style = "width: 100vw; height: 100vh; overflow: auto;",
ggplotly(p3)
)
```

## Bar Plot — Rata-rata Harapan Hidup per Benua
```{r}
p4 <- gapminder %>%
group_by(continent) %>%
summarise(mean_lifeExp = mean(lifeExp)) %>%
ggplot(aes(x = continent, y = mean_lifeExp, fill = continent)) +
geom_col() +
scale_fill_brewer(palette = "Pastel1") +
labs(
title = "Rata-rata Harapan Hidup per Benua (1952–2007)",
x = "Benua",
y = "Rata-rata Harapan Hidup"
) +
theme_minimal(base_size = 14)

htmltools::div(
style = "width: 100vw; height: 100vh; overflow: auto;",
ggplotly(p4)
)
```

## Density Plot — Sebaran Harapan Hidup per Benua
```{r}
p5 <- ggplot(gapminder, aes(x = lifeExp, fill = continent)) +
geom_density(alpha = 0.6) +
scale_fill_brewer(palette = "Pastel2") +
labs(
title = "Sebaran Harapan Hidup per Benua",
x = "Harapan Hidup",
y = "Kepadatan"
) +
theme_light(base_size = 14)

htmltools::div(
style = "width: 100vw; height: 100vh; overflow: auto;",
ggplotly(p5)
)
```