---
title: "IndonesiAPIs: Access Indonesian Data via Public APIs and Curated Datasets"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{IndonesiAPIs: Access Indonesian Data via Public APIs and Curated Datasets}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(IndonesiAPIs)
library(ggplot2)
library(dplyr)
```

# Introduction

The `IndonesiAPIs` package provides a unified interface to access open data from the **World Bank API**, **Nager.Date API**, and the **REST Countries API**, with a focus on **Indonesia**. It allows users to retrieve up-to-date or historical information on topics such as economic indicators, population statistics, national holidays, and basic geopolitical details.

In addition to API-access functions, the package includes a curated collection of open datasets related to **Indonesia**. These datasets cover a wide range of topics including consumer prices, poverty probability, food prices by region, tourism destinations, and minimum wage statistics.

`IndonesiAPIs` is designed to support users working with data related to **Indonesia** by integrating international RESTful APIs with structured and reliable datasets from public, academic, and governmental sources into a single, easy-to-use R package.

## Functions for IndonesiAPIs

The `IndonesiAPIs` package provides several core functions to access real-time and structured information about **Indonesia** from public APIs such as the **World Bank API**, **Nager.Date**, and the **REST Countries API**.
Below is a list of the main functions included in the package:

- `get_indonesia_child_mortality()`: Get Under-5 Mortality Rate in Indonesia from World Bank

- `get_indonesia_cpi()`: Get Indonesia's Consumer Price Index from World Bank

- `get_indonesia_energy_use()`: Get Indonesia's Energy Use (kg of oil equivalent per capita) from World Bank

- `get_indonesia_gdp()`: Get Indonesia's GDP (Current US$) from World Bank

- `get_indonesia_holidays()`: Get official public holidays in Indonesia for a given year, e.g. get_indonesia_holidays(2025)

- `get_indonesia_hospital_beds()`: Get Hospital Beds per 1,000 People in Indonesia from World Bank

- `get_indonesia_life_expectancy()`: Get Indonesia's Life Expectancy at Birth from World Bank

- `get_indonesia_literacy_rate()`: Get Indonesia's Literacy Rate (Age 15+) from World Bank

- `get_indonesia_population()`: Get Indonesia's Total Population from World Bank

- `get_indonesia_unemployment()`: Get Indonesia's Unemployment Rate from World Bank

- `get_country_info_idn()`: Get Key Country Information About Indonesia from the REST Countries API

- `view_datasets_IndonesiAPIs()`: View Available Datasets in IndonesiAPIs

These functions allow users to access high-quality and structured information on **Indonesia**, which can be combined with tools like **dplyr** and **ggplot2** to support a wide range of data analysis, visualization, and research tasks. In the following sections, you'll find examples on how to work with `IndonesiAPIs` in practical scenarios.

### Indonesia's GDP (Current US$) from World Bank 2022 - 2017

```{r indonesia-gdp,echo = TRUE,message = FALSE,warning = FALSE,results = 'markup'}


indonesia_gdp <- head(get_indonesia_gdp())

print(indonesia_gdp)

```


### Indonesia's Life Expectancy at Birth from World Bank 2022 - 2017

```{r indonesia-life-expectancy,echo = TRUE,message = FALSE,warning = FALSE,results = 'markup'}

indonesia_life_expectancy <- head(get_indonesia_life_expectancy())

print(indonesia_life_expectancy)

```

### Indonesia's Total Population from World Bank 2022 - 2017

```{r indonesia-population,echo = TRUE,message = FALSE,warning = FALSE,results = 'markup'}

indonesia_population <- head(get_indonesia_population())

print(indonesia_population)

```


## Top 10 Regions with Highest Average Minimum Wage (2015-2023)

```{r indonesia-wage-plot, message=FALSE, warning=FALSE, fig.width=9, fig.height=5}


# Bar chart with better formatted x-axis
indonesia_minwage_tbl_df %>%
  filter(YEAR >= 2015) %>%
  group_by(REGION) %>%
  summarise(avg_salary = mean(SALARY, na.rm = TRUE), .groups = 'drop') %>%
  arrange(desc(avg_salary)) %>%
  slice_head(n = 10) %>%
  ggplot(aes(x = reorder(REGION, avg_salary), y = avg_salary)) +
  geom_col(fill = "steelblue", alpha = 0.8) +
  coord_flip() +
  scale_y_continuous(
    labels = function(x) format(x, big.mark = ",", scientific = FALSE)
  ) +
  labs(
    title = "Top 10 Regions with Highest Average Minimum Wage (2015-2023)",
    subtitle = "Indonesian Minimum Wage by Region",
    x = "Region",
    y = "Average Minimum Wage (IDR)",
    caption = "Source: IndonesiAPIs package"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 14, face = "bold"),
    plot.subtitle = element_text(size = 12),
    axis.text = element_text(size = 10),
    axis.title = element_text(size = 11)
  )

```

## Dataset Suffixes

Each dataset in `IndonesiAPIs` is labeled with a *suffix* to indicate its structure and type:

- `_df`: A standard data frame.

- `_tbl_df`: A tibble data frame object.


## Datasets Included in IndonesiAPIs

In addition to API access functions, `IndonesiAPIs` offers a curated collection of open datasets focused on **Indonesia**. These preloaded datasets cover a wide range of topics including consumer prices, poverty probability, food prices by region, tourism destinations, and minimum wage statistics. Below are some featured examples:

- `Bali_tbl_df`: A tibble containing food price data in Bali, Indonesia.

- `indonesia_minwage_tbl_df`: A tibble containing monthly minimum wage or Upah Minimum Regional (UMR) data in Indonesian Rupiah (IDR) across various regions of Indonesia from 1997 to 2025.

- `DKIJakarta_tbl_df`: A tibble containing food price data in DKI Jakarta, Indonesia.

## Conclusion

The `IndonesiAPIs` package offers a unified interface for accessing both real-time data from public APIs and a curated collection of datasets about **Indonesia**. Covering a wide spectrum of topics from economic indicators, holidays, and demographic statistics via international APIs, to detailed datasets on consumer prices, poverty probability, food prices by region, tourism destinations, and minimum wage statistics, `IndonesiAPIs` provides users with reliable, structured, and high-quality data.

Designed to support reproducible research, education, and data journalism, the package empowers users to analyze and visualize **Indonesia**-focused data directly within R, using tidy formats and well-documented sources.

<div class="tocify-extend-page" data-unique="tocify-extend-page" style="height: 0;"></div>
