IT,TUR,US Nufus Populasiyonu -Population growth (annual %)-
library(WDI)
df = WDI(indicator='SP.POP.GROW', country=c('IT','TR','US'), start=1999, end=2020)
head(df)
## country iso2c iso3c year SP.POP.GROW
## 1 Italy IT ITA 2020 -0.48709509
## 2 Italy IT ITA 2019 -1.15302842
## 3 Italy IT ITA 2018 -0.19006364
## 4 Italy IT ITA 2017 -0.14986112
## 5 Italy IT ITA 2016 -0.16988407
## 6 Italy IT ITA 2015 -0.09637613
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
df <- df %>%
rename(ulkekodu = 1,
ulke = 2,
nufus = 3,
sene = 4)
library(tidyr)
data_genis <- spread(df, key = ulke, value = nufus)
head(data_genis)
## ulkekodu sene SP.POP.GROW IT TR US
## 1 Italy 1999 0.01682084 ITA <NA> <NA>
## 2 Italy 2000 0.04530363 ITA <NA> <NA>
## 3 Italy 2001 0.05616760 ITA <NA> <NA>
## 4 Italy 2002 0.14891643 ITA <NA> <NA>
## 5 Italy 2003 0.44450731 ITA <NA> <NA>
## 6 Italy 2004 0.64718271 ITA <NA> <NA>
tsveri <- ts(data_genis[,-1], start=1988, frequency=1)
head(tsveri)
## sene SP.POP.GROW IT TR US
## [1,] 1999 0.01682084 1 NA NA
## [2,] 2000 0.04530363 1 NA NA
## [3,] 2001 0.05616760 1 NA NA
## [4,] 2002 0.14891643 1 NA NA
## [5,] 2003 0.44450731 1 NA NA
## [6,] 2004 0.64718271 1 NA NA
library(ggplot2)
library(ggfortify)
autoplot(tsveri[, "TR"]) +
ggtitle("Türkiye'nin Nufus Populasiyonu") +
xlab("Sene") +
ylab("")
## Warning: Removed 44 rows containing missing values (`geom_line()`).

autoplot(tsveri[,"TR"], ts.colour = 'red', ts.linetype = 'dashed')
## Warning: Removed 44 rows containing missing values (`geom_line()`).

plot(tsveri[,"TR"])

plot(tsveri[,2:4])

plot(tsveri[,2:4], plot.type = "single")

plot(tsveri[,2],
type = "l",
col = 2,
ylim = c(0, 25),
xlab = "Sene",
ylab = "Nufus")
lines(tsveri[,3],
type = "l",
col = 3)
lines(tsveri[,4],
type = "l",
col = 4)
legend("topright",
c("Italya", "Türkiye", "US"),
lty = 1,
col = 2:4)

data_uzun <- reshape2::melt(data_genis, id.vars = "sene")
ggplot(data_uzun,
aes(x = sene,
y = value,
col = variable)) +
geom_line()
