-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
111 lines (83 loc) · 3.12 KB
/
README.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
```
# ggHoriPlot: horizon plots in ggplot2 <img src='man/images/sticker_ggHoriPlot.png' align="right" height="180" >
<!-- badges: start -->
[![R-CMD-check](https://github.com/rivasiker/ggHoriPlot/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/rivasiker/ggHoriPlot/actions/workflows/check-standard.yaml)
[![CRAN](https://www.r-pkg.org/badges/version/ggHoriPlot)](https://CRAN.R-project.org/package=ggHoriPlot)
[![downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggHoriPlot)](https://CRAN.R-project.org/package=ggHoriPlot)
[![codecov](https://codecov.io/gh/rivasiker/ggHoriPlot/branch/master/graph/badge.svg?token=8V5E63YVM2)](https://app.codecov.io/gh/rivasiker/ggHoriPlot)
<!-- badges: end -->
This package allows building horizon plots in ggplot2. You can learn more about the package in `vignette("ggHoriPlot")`.
## Installation
You can install `ggHoriPlot` from CRAN via:
``` r
install.packages("ggHoriPlot")
```
You can also install the development version of the package from GitHub with the following command:
``` r
#install.packages("devtools")
devtools::install_github("rivasiker/ggHoriPlot")
```
## Basic example
Load the libraries:
```{r libraries, warning=FALSE, message=FALSE}
library(tidyverse)
library(ggHoriPlot)
library(ggthemes)
```
Load the dataset and calculate the cutpoints and origin:
```{r set}
utils::data(climate_CPH)
cutpoints <- climate_CPH %>%
mutate(
outlier = between(
AvgTemperature,
quantile(AvgTemperature, 0.25, na.rm=T)-
1.5*IQR(AvgTemperature, na.rm=T),
quantile(AvgTemperature, 0.75, na.rm=T)+
1.5*IQR(AvgTemperature, na.rm=T))) %>%
filter(outlier)
ori <- sum(range(cutpoints$AvgTemperature))/2
sca <- seq(range(cutpoints$AvgTemperature)[1],
range(cutpoints$AvgTemperature)[2],
length.out = 7)[-4]
round(ori, 2) # The origin
round(sca, 2) # The horizon scale cutpoints
```
Build the horizon plots in `ggplot2` using `geom_horizon()`:
```{r CPH_climate}
climate_CPH %>% ggplot() +
geom_horizon(aes(date_mine,
AvgTemperature,
fill = ..Cutpoints..),
origin = ori, horizonscale = sca) +
scale_fill_hcl(palette = 'RdBu', reverse = T) +
facet_grid(Year~.) +
theme_few() +
theme(
panel.spacing.y=unit(0, "lines"),
strip.text.y = element_text(size = 7, angle = 0, hjust = 0),
axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
panel.border = element_blank()
) +
scale_x_date(expand=c(0,0),
date_breaks = "1 month",
date_labels = "%b") +
xlab('Date') +
ggtitle('Average daily temperature in Copenhagen',
'from 1995 to 2019')
```
## Learn more
You can check out the full functionality of `ggHoriPlot` in the following guides:
- [Getting started](https://rivasiker.github.io/ggHoriPlot/articles/ggHoriPlot.html)
- [Examples with real data](https://rivasiker.github.io/ggHoriPlot/articles/examples.html)