Search This Blog

A bar graph comparing the GDP of Ethiopia and Kenya


To create a bar graph comparing the GDP of Ethiopia and Kenya using R, you can first use the WDI package to download the GDP data for both countries from the World Bank's World Development Indicators database. Here is a sample code to do that:

This code will download the GDP data for Ethiopia and Kenya for the years 2010 to 2020 and print it to the console. The data will be returned as a data frame with columns for the country, year, and GDP value. 

Once you have the GDP data, you can use the ggplot2 package to create a bar graph comparing the GDP of the two countries for a specific year. Here is a sample code to do that:

This code appears to be creating a bar chart using the ggplot2 package in R. The ggplot function is used to initialize the plot, with the df1 data frame specified as the input data. The geom_bar function is then used to add a bar chart to the plot, with the x aesthetic set to the yrs column from df1 and the y aesthetic set to the NY.GDP.MKTP.CD column from df1. The fill aesthetic is mapped to the country column, and the stat and position parameters are set to "identity" and "dodge" respectively. The scale_fill_manual function is then used to set the colors of the bars to "red" and "blue" for Ethiopia and Kenya respectively. The labs function is used to set the labels for the x and y axes, and the theme_bw function is used to set the base font size for the plot to 14 and the bar graph will have a title of "GDP Comparison".  The output will be:


0 Comments:

Post a Comment