DON’T FORGET

# pd_df %>% 
#   dplyr::select(where(is.numeric)) %>% 
#   skimr::skim(.) %>% 
#   dplyr::select(skim_variable, complete_rate, numeric.mean, numeric.sd, numeric.p50) %>% 
#   kable() %>% kable_styling(font_size = 12)

Compare democracies and non-democracies

Compare across adminstrations

densityplot(~log(pd_budget_per_capita + 1)| president, data = pd_df)

aggregate(budget ~ president, data = pd_df, FUN = mean)
##   president  budget
## 1     Obama 3536611
## 2     Trump 2443519

Compute the average price in each bin of the histogram

In that case, we need to extract the bin breaks from the histogram. We could then create a new categorical variable using the breaks with cut It turns out that extracting the bins is much easier using base graphics than ggplot2, so let’s do that:

pd_df %>% 
  filter(!is.na(region_un)) %>% 
ggplot(aes(log(pd_budget_per_gdp), log(military_exp_per_gdp))) +
      geom_point(aes(color = region_un)) + facet_wrap(~year) -> p

ggplotly(p)