You are on page 1of 1

```{r}

library(readxl)
library(tidyverse)
```

```{r}
fname = file.path("ME315","WDI","WDIEXCEL.xlsx")
fname
file.exists(fname)
```

```{r}
#args(read_excel)
countries <- read_excel(fname,sheet="Country")
head(countries)
```

```{r}
countries <- countries %>%
filter(`Country Code` %in% c("BRA", "AFG", "CHN", "USA", "FRA"))
countries
```

```{r}
WDI <- read_excel(fname, sheet = "Data")
head(WDI)
```

```{r}
WDI2 = WDI %>% select(-c("Country Name", "Indicator Name"))
head(WDI2)
```

```{r}
WDI3 <- WDI2 %>% gather(key = "ANO", value = "VALOR", `1960`:`2018`)
```

```{r}
WDI4 <- WDI3 %>% spread(key = `Indicator Code`, value = "VALOR")
WDI4
```

```{r}
WDI4$ANO <- as.integer(WDI4$ANO)
head(WDI4)
```

```{r}
WDI5 <- WDI4 %>% inner_join(y = countries, by = "Country Code") %>%
select(`Country Code`, `Short Name`, ANO, SP.DYN.CBRT.IN)
WDI5
```

```{r}
WDI6 <- WDI5 %>% arrange(`Country Code`, ANO)
```

```{r}
ggplot(data = WDI6, aes(x = ANO, y = SP.DYN.CBRT.IN, colour = `Country Code`)) +
geom_line() +
labs(x = "Ano", y = "Nascimentos por 1000 Habitantes") +
theme_bw()
```

You might also like