![]() So, I will start with making a graph for a single country using the code below. When I write loops to mass produce graphs, I follow a simple two step process: first, write the code to make the graphs, then figure out what actually need to change to make a the same graph but with different parameters This may seem simple, but I think for beginners it is important to break it down so you don’t get lost in trying to both learn how to do a task and automate it at the same time. Select(indicator, country, iso3c, date, gdp_pct_growth) %>% ![]() I have only included the most relevant variables. Below, you can see how the dataset looks based on a random sample of rows. ![]() In this case we are only working with one indicator but I still prefer working with long data since it works better with ggplot2 when graphing multiple indicators. The result is a long dataset with a row for each indicator–country–year. Since there are so many different indicators, I actually prefer using the web interface. To find the indicator codes you can either use the function wb_search or just go to the World Bank’s online database and find it there. You can change what indicators you want to pull by using the indicator argument. Here I am grabbing the GDP annual % growth rate, only for countries (excluding regional classifications), between 20. # create new variable so that that gdp_pct_growth is formatted as % The wbstats package makes grabbing data from the World Bank’s database very easy. Since I’ve always worked in the political science world, we are going to look at data from the World Bank. To start with we are going to need to get some example data. The final product will be a single PowerPoint with a slide for each country showing the GDP annual % growth from 2009-2019.Īt the end of the post, I’ll go through briefly another way of tackling this problem using functional programming instead of for loops.Īll of the code used here is also avaiable on GitHub, including the PowerPoint materials
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |