Using ggplot, viridis, season and gridExtra, RMD
library (ggplot2) #used to generate graphs
## Warning: package 'ggplot2' was built under R version 3.3.3
library (viridis) #for color pallete
library (season) #I used the indoor dataset from this package. It can be applied to any time series analysis dataset
## Loading required package: MASS
## Loading required package: mgcv
## Loading required package: nlme
## This is mgcv 1.8-15. For overview type 'help("mgcv-package")'.
## Loading required package: survival
## Loading required package: coda
library (gridExtra) #useful if you want to stack many grids within one graph
data(schz)
d <-schz
head(d) #brief look at the data
## year month yrmon NBirths SczBroad SOI
## 1 1930 1 1930.000 1578 8 12.7
## 2 1930 2 1930.083 1519 11 7.7
## 3 1930 3 1930.167 1630 15 1.8
## 4 1930 4 1930.250 1607 12 -3.8
## 5 1930 5 1930.333 1566 10 2.1
## 6 1930 6 1930.417 1491 8 -5.5
tail(d) #verify data collected normally
## year month yrmon NBirths SczBroad SOI
## 499 1971 7 1971.500 3466 12 1.6
## 500 1971 8 1971.583 3285 14 14.9
## 501 1971 9 1971.667 3320 8 15.9
## 502 1971 10 1971.750 3080 6 17.7
## 503 1971 11 1971.833 2979 2 7.2
## 504 1971 12 1971.917 3292 4 2.1
summary(d) # summary of dataset
## year month yrmon NBirths
## Min. :1930 Min. : 1.00 Min. :1930 Min. :1302
## 1st Qu.:1940 1st Qu.: 3.75 1st Qu.:1940 1st Qu.:1694
## Median :1950 Median : 6.50 Median :1951 Median :2436
## Mean :1950 Mean : 6.50 Mean :1951 Mean :2341
## 3rd Qu.:1961 3rd Qu.: 9.25 3rd Qu.:1961 3rd Qu.:2844
## Max. :1971 Max. :12.00 Max. :1972 Max. :3517
## NA's :1
## SczBroad SOI
## Min. : 2.00 Min. :-31.9000
## 1st Qu.:11.00 1st Qu.: -4.7000
## Median :15.00 Median : 0.9000
## Mean :16.01 Mean : 0.7988
## 3rd Qu.:20.00 3rd Qu.: 6.7000
## Max. :36.00 Max. : 26.9000
## NA's :1
dd <-ggplot(d, aes(year, month, fill = SczBroad)) +
geom_tile(colour="gray20", size=1.5, stat="identity") +
scale_fill_viridis(option="H") +
scale_y_continuous(breaks=1:12, labels=month.abb[1:12])+
xlab("") +
ylab("") +
ggtitle("Total Australian Schizophrenics Born By Month and Year") +
theme(
plot.title = element_text(color="white",hjust=0,vjust=1, size=rel(2)),
plot.background = element_rect(fill="gray20"),
panel.background = element_rect(fill="gray20"),
panel.border = element_rect(fill=NA,color="gray20", size=0.5, linetype="solid"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.text = element_text(color="white", size=rel(1.5)),
axis.text.y = element_text(hjust=1),
legend.text = element_text(color="white", size=rel(1.3)),
legend.background = element_rect(fill="gray20"),
legend.position = "bottom",
legend.title=element_blank()
)
## Warning in viridis(256, alpha, begin, end, option): Option 'H' does not
## exist. Defaulting to 'viridis'.