library(WDI 
library(ggplot2) 
library(mFilter)
WDIsearch(string='NY.GDP.MKTP.KD', field="indicator")
##      indicator           name                     
## [1,] "NY.GDP.MKTP.KD"    "GDP (constant 2000 US$)"
## [2,] "NY.GDP.MKTP.KD.ZG" "GDP growth (annual %)"
# "NY.GDP.MKTP.KD" "GDP (constant 2000 US$)" 
data <- WDI(indicator='NY.GDP.MKTP.KD', country=c('DE','FR'), start=1970)

ggplot(data, aes(year, NY.GDP.MKTP.KD, color=country)) + geom_line() + xlab('Year') + ylab('GDP (constant 2000 US$)') 

data <-  data[order(data$year),]

gdpDE <- subset(data, country=="Germany", select=NY.GDP.MKTP.KD)
gdpDE <- ts(gdpDE, start=1970)

gdpFR <- subset(data, country=="France", select=NY.GDP.MKTP.KD)
gdpFR <- ts(gdpFR, start=1970)
# potencialny HDP
hpDE <- hpfilter(gdpDE, freq=100, type="lambda")$trend
hpFR <- hpfilter(gdpFR, freq=100, type="lambda")$trend

# produkcna medzera ako podiel z potencialneho HDP v percentach
podielDE <- 100*(gdpDE-hpDE)/hpDE 
podielFR <- 100*(gdpFR-hpFR)/hpFR
plot(podielDE, type="l", ylab="100*(produkcna medzera)/(potencialny HDP)")
lines(podielFR, col="blue")
abline(h=0, col="grey")

plot(as.vector(podielDE), as.vector(podielFR),
     xlab="Nemecko", ylab="Francuzsko",
     main="Produkcna medzera ako podiel z potencialneho HDP v percentach")

cor(as.vector(podielDE), as.vector(podielFR))
## [1] 0.6939034