Skip to content

Commit b3585f2

Browse files
committed
update ggstackplot Rmd in favor of examples
1 parent 08f5d2a commit b3585f2

File tree

8 files changed

+144
-47
lines changed

8 files changed

+144
-47
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Suggests:
4848
rmarkdown,
4949
testthat (>= 3.0.0),
5050
vdiffr,
51-
scales
51+
scales,
52+
pangaear
5253
Config/testthat/edition: 3
5354
VignetteBuilder: knitr

R/ggstackplot-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ NULL
1010
#' @details
1111
#' `r lifecycle::badge("stable")`
1212
#'
13-
#' 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. Check out the functionality provided by ggstackplots with useful examples and plot styling ideas at <https://ggstackplot.kopflab.org>
13+
#' Have you ever wanted to create (partly) overlapping line plots with matched color-coding of the data and axes? These kinds of plots are common in climatology and oceanography research but there is not an easy way to create them with ggplot facets. The ggstackplot package builds on [ggplot2](https://ggplot2.tidyverse.org/) to provide a straightforward approach to building these kinds of plots while retaining the powerful grammar of graphics approach of ggplots. Check out the functionality provided by ggstackplots at <https://ggstackplot.kopflab.org>
1414
#'
1515
"_PACKAGE"

README.Rmd

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,82 @@ knitr::opts_chunk$set(
2424

2525
## About
2626

27-
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.
27+
Have you ever wanted to create (partly) overlapping line plots with matched color-coding of the data and axes? These kinds of plots are common, for example, in climatology and oceanography research but there is not an easy way to create them with ggplot facets. The ggstackplot package builds on [ggplot2](https://ggplot2.tidyverse.org/) to provide a straightforward approach to building these kinds of plots while retaining the powerful grammar of graphics functionality of ggplots.
2828

2929
## Installation
3030

31-
You can install ggstackplot from [GitHub](https://github.com/) with:
31+
You can install the development version of ggstackplot from [GitHub](https://github.com/) with:
3232

33-
```{r, eval = FALSE}
34-
if(!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools")
35-
devtools::install_github("KopfLab/ggstackplot")
33+
```
34+
# install.packages("pak")
35+
pak::pak("KopfLab/ggstackplot")
3636
```
3737

3838
## Show me some code
3939

40-
```{r example, fig.width=7, fig.height=7}
40+
```{r mtcars}
4141
library(ggstackplot)
4242
43-
# using the built-in economics dataset in ggplot2
44-
ggplot2::economics |>
43+
# using R's built-in mtcars dataset
44+
mtcars |>
4545
ggstackplot(
4646
# define shared x axis
47-
x = date,
48-
# define stacked y axes
49-
y = c(pce, pop, psavert, unemploy),
50-
# add a color palette
51-
palette = "Set1"
47+
x = mpg,
48+
# define multiple y axes
49+
y = c("weight" = wt, "horsepower" = hp),
50+
# set colors
51+
color = c("#E41A1C", "#377EB8"),
52+
# set to complete overlap
53+
overlap = 1
54+
)
55+
```
56+
57+
## Show me some climate data
58+
59+
```{r, message = FALSE}
60+
# download a recent dataset from the public climate data repository PANGAEA
61+
dataset <- pangaear::pg_data(doi = "10.1594/PANGAEA.967047")[[1]]
62+
63+
# show what some of these data look like
64+
dataset$data[
65+
c("Depth ice/snow [m] (Top Depth)",
66+
"Age [ka BP]",
67+
"[SO4]2- [ng/g] (Ion chromatography)")] |>
68+
head() |> knitr::kable()
69+
```
70+
71+
**These data were kindly made available on [PANGEA](`r dataset$url`) by Sigl et al. (2024).**
72+
73+
Full citation:
74+
75+
> `r dataset$citation`
76+
77+
```{r geodata}
78+
# visualize the data with ggstackplot
79+
dataset$data |>
80+
ggstackplot(
81+
x = "Age [ka BP]",
82+
y = c(
83+
# vertical stack of the measurements through time
84+
"sulfate [ng/g]" = "[SO4]2- [ng/g] (Ion chromatography)",
85+
"δ34S [‰]" = "δ34S [SO4]2- [‰ CDT] (Multi-collector ICP-MS (MC-IC...)",
86+
"Δ33S [‰]" = "Δ33S [SO4]2- [‰ CDT] (Multi-collector ICP-MS (MC-IC...)"
87+
),
88+
# color palette
89+
palette = "Dark2",
90+
# partial overlap of the panels
91+
overlap = 0.4
5292
)
5393
```
5494

5595
## Show me more
5696

57-
```{r example2, fig.width=7, fig.height=4}
97+
```{r economics, fig.width=7, fig.height=4}
5898
library(ggplot2)
5999
60-
# creating a horizontal stack instead of vertical and using some of the many
61-
# customization features available in ggstackplot
100+
# using the built-in economics dataset in ggplot2 to create a horizontal stack
101+
# instead of vertical and using some of the many customization features
102+
# available in ggstackplot
62103
ggplot2::economics |>
63104
ggstackplot(
64105
# define shared y axis
@@ -83,13 +124,12 @@ ggplot2::economics |>
83124
add =
84125
list(
85126
# add points just for 2 plots
86-
`unemployed persons` = geom_point(),
87-
`personal savings rate` = geom_point()
127+
"unemployed persons" = geom_point(),
128+
"personal savings rate" = geom_point()
88129
)
89130
)
90131
```
91132

92133
## What else can I do with ggstackplot?
93134

94135
- check out the **[Features](https://ggstackplot.kopflab.org/articles/features.html)** vignette for full details on all available functionality
95-
- check out the **[Examples](https://ggstackplot.kopflab.org/articles/examples.html)** vignette for scientific data examples

README.md

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,105 @@
1212

1313
## About
1414

15-
Have you ever wanted to compare multiple panels of line plots that do
16-
not share coordinate schemes? These kinds of plots are ubiquitous in the
17-
Earth sciences, but there is not an easy way to create them with ggplot
18-
facets.
15+
Have you ever wanted to create (partly) overlapping line plots with
16+
matched color-coding of the data and axes? These kinds of plots are
17+
common, for example, in climatology and oceanography research but there
18+
is not an easy way to create them with ggplot facets. The ggstackplot
19+
package builds on [ggplot2](https://ggplot2.tidyverse.org/) to provide a
20+
straightforward approach to building these kinds of plots while
21+
retaining the powerful grammar of graphics functionality of ggplots.
1922

2023
## Installation
2124

22-
You can install ggstackplot from [GitHub](https://github.com/) with:
25+
You can install the development version of ggstackplot from
26+
[GitHub](https://github.com/) with:
2327

24-
``` r
25-
if(!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools")
26-
devtools::install_github("KopfLab/ggstackplot")
27-
```
28+
# install.packages("pak")
29+
pak::pak("KopfLab/ggstackplot")
2830

2931
## Show me some code
3032

3133
``` r
3234
library(ggstackplot)
3335

34-
# using the built-in economics dataset in ggplot2
35-
ggplot2::economics |>
36+
# using R's built-in mtcars dataset
37+
mtcars |>
3638
ggstackplot(
3739
# define shared x axis
38-
x = date,
39-
# define stacked y axes
40-
y = c(pce, pop, psavert, unemploy),
41-
# add a color palette
42-
palette = "Set1"
40+
x = mpg,
41+
# define multiple y axes
42+
y = c("weight" = wt, "horsepower" = hp),
43+
# set colors
44+
color = c("#E41A1C", "#377EB8"),
45+
# set to complete overlap
46+
overlap = 1
4347
)
4448
```
4549

46-
<img src="man/figures/README-example-1.png" width="100%" />
50+
<img src="man/figures/README-mtcars-1.png" width="100%" />
51+
52+
## Show me some climate data
53+
54+
``` r
55+
# download a recent dataset from the public climate data repository PANGAEA
56+
dataset <- pangaear::pg_data(doi = "10.1594/PANGAEA.967047")[[1]]
57+
58+
# show what some of these data look like
59+
dataset$data[
60+
c("Depth ice/snow [m] (Top Depth)",
61+
"Age [ka BP]",
62+
"[SO4]2- [ng/g] (Ion chromatography)")] |>
63+
head() |> knitr::kable()
64+
```
65+
66+
| Depth ice/snow \[m\] (Top Depth) | Age \[ka BP\] | \[SO4\]2- \[ng/g\] (Ion chromatography) |
67+
|---------------------------------:|--------------:|----------------------------------------:|
68+
| 160.215 | 1.20662 | 52.00 |
69+
| 160.183 | 1.20300 | 165.00 |
70+
| 160.151 | 1.20276 | 93.50 |
71+
| 160.022 | 1.20191 | 42.25 |
72+
| 159.990 | 1.20155 | 74.50 |
73+
| 159.958 | 1.20130 | 104.50 |
74+
75+
**These data were kindly made available on
76+
[PANGEA](https://doi.org/10.1594/PANGAEA.967047) by Sigl et
77+
al. (2024).**
78+
79+
Full citation:
80+
81+
> Sigl, Michael; Gabriel, Imogen; Hutchison, William; Burke, Andrea
82+
> (2024): Sulfate concentration and sulfur isotope data from Greenland
83+
> TUNU2013 ice-core samples between 740-765 CE \[dataset\]. PANGAEA,
84+
> <https://doi.org/10.1594/PANGAEA.967047>
85+
86+
``` r
87+
# visualize the data with ggstackplot
88+
dataset$data |>
89+
ggstackplot(
90+
x = "Age [ka BP]",
91+
y = c(
92+
# vertical stack of the measurements through time
93+
"sulfate [ng/g]" = "[SO4]2- [ng/g] (Ion chromatography)",
94+
"δ34S [‰]" = "δ34S [SO4]2- [‰ CDT] (Multi-collector ICP-MS (MC-IC...)",
95+
"Δ33S [‰]" = "Δ33S [SO4]2- [‰ CDT] (Multi-collector ICP-MS (MC-IC...)"
96+
),
97+
# color palette
98+
palette = "Dark2",
99+
# partial overlap of the panels
100+
overlap = 0.4
101+
)
102+
```
103+
104+
<img src="man/figures/README-geodata-1.png" width="100%" />
47105

48106
## Show me more
49107

50108
``` r
51109
library(ggplot2)
52110

53-
# creating a horizontal stack instead of vertical and using some of the many
54-
# customization features available in ggstackplot
111+
# using the built-in economics dataset in ggplot2 to create a horizontal stack
112+
# instead of vertical and using some of the many customization features
113+
# available in ggstackplot
55114
ggplot2::economics |>
56115
ggstackplot(
57116
# define shared y axis
@@ -76,19 +135,16 @@ ggplot2::economics |>
76135
add =
77136
list(
78137
# add points just for 2 plots
79-
`unemployed persons` = geom_point(),
80-
`personal savings rate` = geom_point()
138+
"unemployed persons" = geom_point(),
139+
"personal savings rate" = geom_point()
81140
)
82141
)
83142
```
84143

85-
<img src="man/figures/README-example2-1.png" width="100%" />
144+
<img src="man/figures/README-economics-1.png" width="100%" />
86145

87146
## What else can I do with ggstackplot?
88147

89148
- check out the
90149
**[Features](https://ggstackplot.kopflab.org/articles/features.html)**
91150
vignette for full details on all available functionality
92-
- check out the
93-
**[Examples](https://ggstackplot.kopflab.org/articles/examples.html)**
94-
vignette for scientific data examples

man/figures/README-economics-1.png

271 KB
Loading

man/figures/README-geodata-1.png

356 KB
Loading

man/figures/README-mtcars-1.png

214 KB
Loading

man/ggstackplot-package.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)