![]() 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) + Mutate(income_grp = ifelse(income_grp = "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. #' radius radius for inner and outer pie (usually in )ĭonuts <- function(x, group = 1, labels = NA, col = NULL, radius = c(.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. ![]() #' labels vector of labels for individual slices #' group vector identifying the group for each slice Here is a much shorter version which does most of the work with a much simpler interface. The problem is, how do I combine the two to look like the topmost image? I have tried many ways, such as: ggplot(browsers) + geom_rect(aes(fill=version, ymax=ymax, ymin=ymin, xmax=4, xmin=3)) + geom_bar(aes(x = factor(1), fill = browser),width = 1) + coord_polar(theta="y") + xlim(c(0, 4))īut all my results are either twisted or end with an error message. ![]() Ggplot(browsers) + geom_bar(aes(x = factor(1), fill = browser),width = 1) + the donut chart of the versions, and the pie chart of the browsers) like so: ggplot(browsers) + geom_rect(aes(fill=version, ymax=ymax, ymin=ymin, xmax=4, xmin=3)) + So far, I have plotted the individual components (i.e. ![]() I have exactly the same data: browsers browsers I am trying to replicate this with R ggplot.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |