-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
64 lines (49 loc) · 1.82 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: "Radial time-series with R"
output:
html_document:
df_print: paged
---
```{r, message= FALSE}
require(TSclust)
require(dplyr)
require(chron)
require(zoo)
require("ggplot2")
require("viridis")
require("scales")
```
# Reading dataset
The dataset that we use contains the number of births per month in New York city, from January 1946 to December 1959. This data is stored in the file https://robjhyndman.com/tsdldata/data/nybirths.dat. We can read this data directly from R, as follows:
Reference: http://a-little-book-of-r-for-time-series.readthedocs.io/en/latest/src/timeseries.html
```{r, message= FALSE}
number_births <- scan("https://robjhyndman.com/tsdldata/data/nybirths.dat")
ts_number_births <- ts(number_births, frequency=12, start=c(1946,1))
plot(ts_number_births)
```
# Transforming data in a data frame
```{r}
df_number_births = data.frame(value=as.matrix(ts_number_births), date=as.Date(as.yearmon(time(ts_number_births))) )
```
# Visualizing time-serie
Inspired by http://jkunst.com/r/how-to-weather-radials/
```{r, fig.height = 5, fig.width= 5}
ggplot(df_number_births, aes(x = date, y = value, color = value )) +
geom_line(size = 1) +
coord_polar() +
scale_colour_viridis(option = "A") +
scale_x_date(labels = date_format("%Y"), breaks = date_breaks("year")) +
ylim(0, 32) +
labs(title = "Number of births per month in New York city",
subtitle = "from January 1946 to December 1959",
color = NULL,
x = NULL, y = NULL) +
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position="bottom",
legend.key.width=unit(1,"cm"),
legend.key.height=unit(0.25,"cm"),
legend.text=element_text(size=7),
text = element_text(size = 12),
panel.background = element_rect(fill = "white", colour = "white"))
```