![]() Ggplot(aes(fill = income_grp, values = n)) + Mutate(income_grp = ifelse(income_grp = "1. We can also add theme_enhance_waffle() to make the graph cleaner and less cluttered. ![]() each value n will be replaced with n/ sum(n)) default is FALSE ![]() make_proportional – if we set to TRUE, compute proportions from the raw values? (i.e.flip – set to TRUE or FALSE for whether you want the coordinates horizontal or vertically stacked.color – I will set to white for the lines in the graph, the default is black but I think that can look a bit too busy.size – again we can play around with this number to see what looks best.n_rows – rhe default is 10 but this is something you can play around with to see how long or wide you want the chart.When we add the waffle::geom_waffle() there are some arguments we can customise. So, instead, install the following version: remotes::install_github("hrbrmstr/waffle") I made the mistake of installing the non-github version and nothing worked. It is important we do not install the CRAN version, but rather the version in development. Ggtitle(label = "Number of countries per region") Labels = c("High Income", "Upper Middle Income", "Lower Middle Income", "Low Income"), Ggplot(aes(reorder(n, income_grp), n, fill = as.factor(income_grp))) +Ĭoord_polar("x", start = 0, direction = - 1) + We can compare to the number of countries in each region : states_df %>% Ggtitle(label = "Primary Energy Consumption across income levels since 1900", subtitle = "Source: Correlates of War CINC") Labels = c("High Income", "Upper Middle Income", "Lower Middle Income", "Low Income"), name = "Income Level") + ![]() Ggplot(aes(x = reorder(sum_pec, income_grp), y = sum_pec, fill = as.factor(income_grp))) +Ĭoord_polar("x", start = 0, direction = -1) + Summarise(sum_pec = sum(pec, na.rm = TRUE)) %>% Next we add a UN location code so we can easily merge both datasets we downloaded! states$un_code % ![]() To download them in one line of code, we use the create_stateyears() function from the peacesciencer package.Ĭlick here to read more about downloading Correlates of War and other IR variables from the peacesciencer package It serves as the basis for the most widely used indicator of national capability, CINC (Composite Indicator of National Capability) and covers the period 1816-2016. These variables – which attempt to operationalize a country’s power – are military expenditure, military personnel, energy consumption, iron and steel production, urban population, and total population. Next, we will download national military capabilities (NMC) dataset. region_var$un_code <- countrycode(region_var$name_long, "country.name", "un") Click here to learn more about countrycode() function. Select(name_long, subregion, income_gr) %>% as_data_frame() -> region_varĪnd add a variable of un_code that it will be easier to merge datasets in a bit. I’m going to compare regions around the world on their total energy consumption levels since the 1900s.įirst, we can download the region data with information about the geography and income levels for each group, using the ne_countries() function from the rnaturalearth package. When the slices aren’t equal, as often is the case with real-world data, it’s difficult to envision the parts of a whole pie chart accurately.īelow are some slight alternatives that we can turn to and visualise different values across groups. If we want to convey nuance in the data, sometimes that information is lost if we display many groups in a pie chart.Īccording to Bernard Marr, our brains are used to equal slices when we think of fractions of a whole. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |