![]() Mutate(income_grp = ifelse(income_grp = "1. 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. Ggplot(z, aes(x=factor(1), rain, fill=as.factor(paste(Months,rain, sep=" - ")))) + geom_bar(stat="identity", width=1) + ggtitle("Rainfall - 2014")+coord_polar(theta = "y")+xlab("")+ylab("")+theme(legend.position="right", legend.title=element_blank(), plot.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. India_rain$y = india_rain$rain/2 + c(0, cumsum(india_rain$rain)) ![]() This give angle in which pie label display. Ggplot(india_rain, aes(x=factor(1), rain, fill=as.factor(paste(Months,rain, sep=" - ")))) + geom_bar(stat="identity", width=1) + ggtitle("Rainfall - 2014")+coord_polar(theta = "y")Ībove pie chart was a basic pie chart we can generate using ggplot. India_rain=read.csv("rainfall_2014.csv", header=T, sep=",", stringsAsFactors=FALSE) I am using the same data of my previous post. Lets try to plot pie chart using ggplot2. In my previous post, I discussed about how to draw basic pie chart. Theme(legend.position = "none", axis.ticks = element_blank(), = element_text(angle = 45, hjust = 1, face="bold", size=15), = element_text(face="bold", size=9)) + scale_fill_gradient(low = "white", high = "steelblue")Ĭricket is a batsman game and I used top 50 run scorer to generate heat map. Ggplot(ipl.d, aes(variable, Player)) + geom_tile(aes(fill = rescale), colour = "white") + labs(x = "", y = "") + scale_x_discrete(expand = c(0, 0)) + scale_y_discrete(expand = c(0, 0)) + Ggplot(ipl.d, aes(variable, Player)) + geom_tile(aes(fill = rescale), colour = "white") + scale_fill_gradient(low = "white", high = "steelblue")Ībove heatmap is raw, Lets try to beautify the same heatmap. (variable), transform, rescale = rescale(value)) ![]() I am using IPL 2014 top 50 run score data. Ggplot has no special syntax for heatmap, it uses combination of geom_title and scale_fill_gradient to plot heatmap. To begin with, I am using below libraries Lets try to generate heat map using ggplot library. ![]() In one of my previous ggplot post, I gave some insight on line, point, bar chart.
0 Comments
Leave a Reply. |