Column

Private vs. Government Expenditure in Developed Countries in 2019

Column

Out-of-Pocket Spending as % of Current Health Expenditure

Social Health Insurance as % of Current Health Expenditure

---
title: "Like A G-7 (Group of 7 Developed Countries)"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{r setup, message = FALSE, echo = FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
library(readxl)
```

```{r, include = FALSE}
ghed_df <- 
  read_excel("./data/GHED_data.XLSX")

ghed_df <- ghed_df %>% 
    janitor::clean_names() 

developed_nations <- ghed_df %>%
  filter(country == "Canada" | country == "Japan" | country == "France" | country == "Germany" | country == "Italy" | country == "United Kingdom" | country == "United States of America")

undeveloped_nations <- ghed_df %>%
  filter(country != "Canada" & country != "Japan" & country != "France" & country != "Germany" & country != "Italy" & country != "United Kingdom" & country != "United States of America", year == 2019)
```

Column {data-width=500}
-----------------------------------------------------------------------

### Private vs. Government Expenditure in Developed Countries in 2019
```{r,message=FALSE}
ghed_df %>%
  filter(country == "Canada" | country == "Japan" | country == "France" | country == "Germany" | country == "Italy" | country == "United Kingdom" | country == "United States of America") %>%
  filter(year == 2019) %>%
  select(country, year, gghed_che, pvtd_che) %>%
  mutate(sum_per = gghed_che + pvtd_che) %>%
  pivot_longer(cols = contains("che"),
               names_to = "exp_type",
               values_to = "exp_per") %>%
  mutate(exp_type = replace(exp_type, exp_type == "gghed_che", "Government Expenditure"),
         exp_type = replace(exp_type, exp_type == "pvtd_che", "Private Expenditure")) %>%
  plot_ly(x = ~country, y = ~exp_per, name = ~exp_type, color = ~exp_type, type = 'bar', colors = "viridis") %>%
  layout(yaxis = list(title = 'Percent of Total Expenditure'), xaxis = list(title = "Country", categoryorder = "total descending"), barmode = 'stack', colors = "viridis")

```

Column {data-width=500}
-----------------------------------------------------------------------

### Out-of-Pocket Spending as % of Current Health Expenditure

```{r, message=FALSE}
developed_nations %>%
  filter(year == 2019) %>%
  select(country, oops_che) %>%
  arrange(desc(oops_che)) %>%
  plot_ly(x = ~country, y = ~oops_che, name = ~country, color = ~country, type = 'bar', colors = "viridis") %>%
  add_trace(data = undeveloped_nations, x = ~country, y = ~oops_che, name = ~country, color = ~country, type = 'bar', colors = "viridis", visible = "legendonly") %>% 
  layout(yaxis = list(title = 'OOPS Spending'), xaxis = list(title = "Country"), barmode = 'stack', colors = "viridis") %>%
  layout(xaxis = list(categoryorder = "total descending")) 
```

### Social Health Insurance as % of Current Health Expenditure
```{r, message=FALSE}
developed_nations %>%
  filter(year == 2019) %>%
  select(country, shi_che) %>%
  arrange(desc(shi_che)) %>%
  plot_ly(x = ~country, y = ~shi_che, name = ~country, color = ~country, type = 'bar', colors = "viridis") %>%
    add_trace(data = undeveloped_nations, x = ~country, y = ~shi_che, name = ~country, color = ~country, type = 'bar', colors = "viridis", visible = "legendonly") %>% 
  layout(yaxis = list(title = 'SHI Spending'), xaxis = list(title = "Country"), barmode = 'stack', colors = "viridis") %>%
  layout(xaxis = list(categoryorder = "total descending"))
```