0

Hello I have a data set from the CPI of 20 years i calculated the inflationrate:

"/" <- function(x,y) ifelse(y==0,0,base:::"/"(x,y))

n <- length(CPI.germany$CPI)

infl <- CPI.germany$CPI[13:n]/CPI.germany$CPI[1:(n-12)]

# adjust the date column
date <- CPI.germany1$Date
datenew<- date[13:252]

#control
length(datenew)
length(infl)

 infl    datenew
1    1.08182862 1991-01-15
2    1.08195654 1991-02-15
3    1.08191389 1991-03-15
4    1.22093054 1991-04-15
5    1.28206524 1991-05-15
6    1.56516705 1991-06-15
7    2.01404189 1991-07-15
8    1.58665134 1991-08-15

How can I know create a Time series graph like that one i attached. And which package is the easiest one? ggplot2?

graph

camille
  • 16,432
  • 18
  • 38
  • 60
  • [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a sample of data and all necessary code. Right now this is very broad, and we can't run code on a picture of a table of data. It's unclear what type of chart you want and how you want to go about it (what packages, etc), and removing 12 rows seems like a preprocessing step that's not related to the actual plotting – camille Jan 16 '20 at 19:29
  • Try `ggplot(your_dataset, aes(datenew, infl)) + geom_line()`. The theme in the graph you attached is from the [`hrbrthemes`](https://github.com/hrbrmstr/hrbrthemes) package. – markus Jan 16 '20 at 19:37
  • "Easiest" is subjective and depends on a lot of things: your experience, your audience, your context, etc. – camille Jan 16 '20 at 20:02
  • my experience is not so high; I am a beginner. it is for a School presentation. So it should only conect the Dates with the appropriate growth rates – Laura Müller Jan 16 '20 at 20:05

1 Answers1

0

Assuming DF shown reproducibly in the Note at the end convert to zoo series z and then use one of the methods shown.

library(zoo)
z <- read.zoo(DF, index = "datenew")

# classic graphics
plot(z)

# ggplot2
library(ggplot2)
autoplot(z)

# lattice
library(lattice)
xyplot(z)

Note

Lines <- " infl    datenew
1    1.08182862 1991-01-15
2    1.08195654 1991-02-15
3    1.08191389 1991-03-15
4    1.22093054 1991-04-15
5    1.28206524 1991-05-15
6    1.56516705 1991-06-15
7    2.01404189 1991-07-15
8    1.58665134 1991-08-15"
DF <- read.table(text = Lines)
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341