-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
95 lines (78 loc) · 2.81 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
dpi = 300
)
```
# ggstackplot
<!-- badges: start -->
[![R-CMD-check](https://github.com/KopfLab/ggstackplot/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/KopfLab/ggstackplot/actions/workflows/R-CMD-check.yaml)
[![Documentation](https://img.shields.io/badge/docs-online-green.svg)](https://ggstackplot.kopflab.org/)
[![codecov](https://codecov.io/gh/kopflab/ggstackplot/branch/main/graph/badge.svg?token=SN0YDIJ6Y6)](https://app.codecov.io/gh/kopflab/ggstackplot)
<!-- badges: end -->
## About
Have you ever wanted to compare multiple panels of line plots that do not share coordinate schemes? These kinds of plots are ubiquitous in the Earth sciences, but there is not an easy way to create them with ggplot facets.
## Installation
You can install ggstackplot from [GitHub](https://github.com/) with:
```{r, eval = FALSE}
if(!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools")
devtools::install_github("KopfLab/ggstackplot")
```
## Show me some code
```{r example, fig.width=7, fig.height=7}
library(ggstackplot)
# using the built-in economics dataset in ggplot2
ggplot2::economics |>
ggstackplot(
# define shared x axis
x = date,
# define stacked y axes
y = c(pce, pop, psavert, unemploy),
# add a color palette
palette = "Set1"
)
```
## Show me more
```{r example2, fig.width=7, fig.height=4}
library(ggplot2)
# creating a horizontal stack instead of vertical and using some of the many
# customization features available in ggstackplot
ggplot2::economics |>
ggstackplot(
# define shared y axis
y = date,
# define the stacked x axes with custom axis labels
x = c(
"personal consumption expenditures" = pce,
"population" = pop,
"personal savings rate" = psavert,
"unemployed persons" = unemploy),
# add a different color palette
palette = "Dark2",
# overlay the pce & pop plots and psavert & unemploy plots
overlap = c(1, 0, 1),
# provide a custom plot template
template =
ggplot() +
geom_path() +
theme_stackplot() +
scale_y_date(),
# add plot specific elements
add =
list(
# add points just for 2 plots
`unemployed persons` = geom_point(),
`personal savings rate` = geom_point()
)
)
```
## What else can I do with ggstackplot?
- check out the **[Features](https://ggstackplot.kopflab.org/articles/features.html)** vignette for full details on all available functionality
- check out the **[Examples](https://ggstackplot.kopflab.org/articles/examples.html)** vignette for scientific data examples