library(readxl)
base <- read_excel("C:/Users/daffy/Downloads/Mensuales-20200625-113352.xlsx")
## New names:
## * `` -> ...1
length(base)
## [1] 2
dim(base)
## [1] 426   2
base=base[2:length(base$PN01270PM),]
head(base)
## # A tibble: 6 x 2
##   ...1  PN01270PM          
##   <chr> <chr>              
## 1 Ene85 2.80968486841237E-5
## 2 Feb85 3.07624742660889E-5
## 3 Mar85 3.32683974171694E-5
## 4 Abr85 3.73288342654407E-5
## 5 May85 4.13992580765049E-5
## 6 Jun85 4.62799486747773E-5
fechas<- as.Date("1985-01-01",format="%Y-%m-%d")
fechas<- seq(fechas,length=length(base$...1),by="month")
library(ggplot2)
library(ggthemes)
library(tidyverse)
## -- Attaching packages -------------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.3     v dplyr   1.0.0
## v tidyr   1.1.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## v purrr   0.3.4
## -- Conflicts ----------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
base1<- data.frame(fechas,"IPC"=base$PN01270PM)
head(base1)
##       fechas                 IPC
## 1 1985-01-01 2.80968486841237E-5
## 2 1985-02-01 3.07624742660889E-5
## 3 1985-03-01 3.32683974171694E-5
## 4 1985-04-01 3.73288342654407E-5
## 5 1985-05-01 4.13992580765049E-5
## 6 1985-06-01 4.62799486747773E-5
ata<-ggplot(base1,aes(fechas,IPC))+geom_line(color="#6E6E6E",size=1)
print(ata)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

fechas<- function(a){
  b<-as.character(a)
  as<-as.Date(b,bformat="%Y-%m-%d")
  print(as)
}
daffy<-ata+ annotate("rect",xmin = fechas("1985-01-01")
              ,xmax = as.Date("1990-01-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
              alpha=0.3,color="black",fill="#B40404") +
  annotate("rect",xmin = fechas("1990-01-01")
           ,xmax = as.Date("2000-01-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
           alpha=0.3,color="black",fill="#04B404") +
  annotate("rect",xmin = fechas("2000-01-01")
           ,xmax = as.Date("2001-01-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
           alpha=0.3,color="black",fill="#013ADF") +
  annotate("rect",xmin = fechas("2001-01-01")
           ,xmax = as.Date("2006-01-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
           alpha=0.3,color="black",fill="#AEB404")+
  annotate("rect",xmin = fechas("2006-01-01")
           ,xmax = as.Date("2011-01-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
           alpha=0.3,color="black",fill="#FF8000")+
  annotate("rect",xmin = fechas("2011-01-01")
           ,xmax = as.Date("2016-01-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
           alpha=0.3,color="black",fill="#F7819F")+
  annotate("rect",xmin = fechas("2016-01-01")
           ,xmax = as.Date("2018-01-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
           alpha=0.7,color="black",fill="#E6E6E6")+
  annotate("rect",xmin = fechas("2018-01-01")
           ,xmax = as.Date("2020-05-01",format="%Y-%m-%d"),ymin = -Inf,ymax = +Inf,
           alpha=0.7,color="black",fill="#E0F8F7") +theme_economist_white()
## [1] "1985-01-01"
## [1] "1990-01-01"
## [1] "2000-01-01"
## [1] "2001-01-01"
## [1] "2006-01-01"
## [1] "2011-01-01"
## [1] "2016-01-01"
## [1] "2018-01-01"
daffy
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

ata1<-daffy+labs(title = "Evolucion de la inflacion",subtitle = "Periodo 1985-2020",caption = "Hecho por Sebastian Sosa Péresz \n Fuente BCRP")
ata2<-ata1+ annotate ( "text" , x = fechas("1987-01-01") , y = 50 , label = "Gobierno de \n Alan García(1985-1990)" ,color="black",angle=90)+
  annotate ( "text" , x = fechas("1995-01-01") , y = 50 , label = "Gobierno de \n Alberto Fujimori(1990-2000)" ,color="black",angle=90)+
  annotate ( "text" , x = fechas("2000-06-01") , y = 50 , label = "Gobierno de \n Valentinn Paniagua Corazao(2000-2001)" ,color="black",angle=90)+
  annotate ( "text" , x = fechas("2004-01-01") , y = 50 , label = "Gobierno de \n  Alejandro Toledo Manrique(2001-2006)" ,color="black",angle=90)+
  annotate ( "text" , x = fechas("2008-01-01") , y = 50 , label = "Gobierno de \n   Alan García Pérez(2006-2011) " ,color="black",angle=90)+
  annotate ( "text" , x = fechas("2012-01-01") , y = 50 , label = "Gobierno de \n   Ollanta Moisés Humala Tasso(2011-2016) " ,color="black",angle=90)+
  annotate ( "text" , x = fechas("2016-07-01") , y = 50 , label = "Gobierno de \n    Pedro Pablo Kuczynski Godard(2016-2018) " ,color="black",angle=90)+
  annotate ( "text" , x = fechas("2018-07-01") , y = 50 , label = "Gobierno de \n     Martín Alberto Vizcarra Cornejo(2018-2020) " ,color="black",angle=90)
## [1] "1987-01-01"
## [1] "1995-01-01"
## [1] "2000-06-01"
## [1] "2004-01-01"
## [1] "2008-01-01"
## [1] "2012-01-01"
## [1] "2016-07-01"
## [1] "2018-07-01"
ata2
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?