diff --git a/.gitignore b/.gitignore
index c09c9d3..b695e12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,9 @@
ehthumbs.db
Thumbs.db
+# test files
+tests/**/*.pdf
+
# produced vignettes
vignettes/*.html
vignettes/*.pdf
diff --git a/DESCRIPTION b/DESCRIPTION
index 2d142db..52f72aa 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: ggstackplot
Title: Create Overlapping Stacked Plots
-Version: 0.4
+Version: 0.4.1
Authors@R:
c(person(
given = "Sebastian", family = "Kopf",
@@ -11,7 +11,7 @@ Authors@R:
given = "Tristan", family = "Caro",
email = "tristan.caro@colorado.edu",
role = c("aut"),
- comment = c(ORCID = "")),
+ comment = c(ORCID = "0000-0001-6177-7444")),
person(
given = "Jamie", family = "McFarlin",
email = "jamie.mcfarlin@uwyo.edu",
@@ -27,6 +27,9 @@ Description:
Easily create overlapping grammar of graphics plots for scientific data visualization.
This style of plotting is particularly common in climatology and oceanography research communities.
License: MIT + file LICENSE
+URL: https://ggstackplot.kopflab.org/,
+ https://github.com/kopflab/ggstackplot
+BugReports: https://github.com/kopflab/ggstackplot/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
diff --git a/NEWS.md b/NEWS.md
index 4b0d24f..00ac454 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,10 @@
+# ggstackplot 0.4.1
+
+* clarify the behaviour of the `switch_axes` parameter for horizontal stackplots
+* fix issue #30 to enable transformed shared axes
+* update the features vignette (now called explore) with new examples
+* include an example of a horizontal stackplot in the README
+
# ggstackplot 0.4.0
This is the first public release adding all core ggstackplot functionality.
diff --git a/R/ggstackplot.R b/R/ggstackplot.R
index e43d929..9c12e0c 100644
--- a/R/ggstackplot.R
+++ b/R/ggstackplot.R
@@ -2,7 +2,7 @@
#' Stack a ggplot
#'
-#' Use `ggstackplot()` to generate a stackplot. If you need more fine control, use `prepare_stackplot()` and `assemble_stackplot()` individually.
+#' Use `ggstackplot()` to generate a stackplot. If you need more fine control, use `prepare_stackplot()` and `assemble_stackplot()` individually. To explore examples of all the different features, check out the `vignette("explore", "ggstackplot")` or the [online documentation](https://ggstackplot.kopflab.org/dev/articles/explore.html).
#'
#' @details
#' `ggstackplot()` stacks a ggplot template with the provided data and parameters. It returns a plot object generated by [cowplot::plot_grid()]).
@@ -15,7 +15,7 @@
#' @param palette which color to make the plots defined with an RColorBrewer palette ([RColorBrewer::display.brewer.all()]). You can only use `color` or `palette` parameter, not both.
#' @param both_axes whether to have the stacked axes on both sides (overrides alternate_axes and switch_axes)
#' @param alternate_axes whether to alternate the sides on which the stacked axes are plotted
-#' @param switch_axes whether to switch the stacked axes. Not switching means the first plot in the lower left corner is always arranged like a regular ggplot with the y axis on the left and the x axis on the bottom (even if `alternate_axes = TRUE`). Setting `switch_axes = TRUE`, leads to the opposite, i.e. first plot in the lower corner has the variable axis on the other side (secondary in ggplot terms).
+#' @param switch_axes whether to switch the stacked axes. Not switching means that for vertical stacks the plot at the bottom has the y-axis always on the left side; and for horizontal stacks that the plot on the left has the x-axis on top. Setting `switch_axes = TRUE`, leads to the opposite.
#' @param overlap fractional overlap between adjacent plots. The max of 1 means plots are perfectly overlaid. The min of 0 means there is no overlap. If providing multiple values, must be 1 less than the number of stacked plots (since it's describing the overlap/gap between adjacent plots). By default there is no overlap between plots
#' @param simplify_shared_axis whether to simplify the shared axis to only be on the last plot (+ first plot if a duplicate secondary axis is set)
#' @param shared_axis_size if simplify_shared_axes is true, this determines the size of the shared axis relative to the size of a single plot
@@ -23,7 +23,6 @@
#' @param add a list of ggplot component calls to add to specific panel plots, either by panel variable name (named list) or index (unnamed list)
#' @param debug `r lifecycle::badge("experimental")` debug flag to print the stackplot tibble and gtable intermediates
#' @examples
-#'
#' # 1 step stackplot (most common use)
#' mtcars |>
#' ggstackplot(
@@ -42,6 +41,10 @@
#' ) |>
#' assemble_stackplot(overlap = c(1, 0, 0.3))
#'
+#' @examplesIf interactive()
+#' # many more examples available in the vignette
+#' vignette("explore", "ggstackplot")
+#'
#' @export
#' @returns `ggstackplot()` returns a ggplot with overlayed plot layers
ggstackplot <- function(
@@ -199,7 +202,7 @@ create_stackplot_tibble <- function(
.xvar = factor_in_order(names(x)),
.yvar = factor_in_order(names(y))
) |>
- dplyr::arrange(dplyr::desc(.data$.xvar), .data$.yvar)
+ dplyr::arrange(.data$.xvar, .data$.yvar)
# do we have a valid length for color or palette?
stopifnot("can only set either `color` or `palette`, not both" = is.na(color) | is.na(palette))
@@ -223,9 +226,13 @@ create_stackplot_tibble <- function(
.axis_switch =
if (both_axes) NA else
calculate_axis_switch(
+ # Note: the reverse_factor and reverse = TRUE for 'vertical'
+ # plot are both needed to properly invert the order AND keep
+ # the first plot in the lower left (unless switch = TRUE)
var =
- if (!!direction == "horizontal") .data$.xvar
- else reverse_factor(.data$.yvar),
+ if (!!direction == "vertical")
+ reverse_factor(.data$.yvar)
+ else .data$.xvar,
alternate = {{ alternate_axes }},
switch = {{ switch_axes }},
reverse = !!direction == "vertical"
@@ -313,11 +320,21 @@ create_stackplot_gtables <- function(prepared_stackplot, overlap, simplify_share
call = call)
}
- # combine plots and themes and assembel the gtables
+ # combine plots and themes and assemble the gtables
gtables <- prepared_stackplot |>
combine_plot_theme_add(simplify_shared_axis = simplify_shared_axis, include_adds = TRUE) |>
tidyr::unnest("config") |>
- dplyr::select(".var", ".direction", "plot_w_theme") |>
+ dplyr::select(".var", ".direction", "plot_w_theme")
+
+ # make sure horizontal panels are in the correct order
+ # (reverse since horizontal positioning is inverted relative to vertical
+ # given the combined plot coordinate system starts in lower left corner)
+ if(gtables$.direction[1] == "horizontal") {
+ gtables <- gtables |> dplyr::arrange(dplyr::desc(dplyr::row_number()))
+ overlap <- rev(overlap)
+ }
+
+ gtables <- gtables |>
# could think about relative sizing here with size_adjust but that doesn't seem like a feature we need
dplyr::mutate(
size = 1,
diff --git a/R/helpers.R b/R/helpers.R
index 99cb76d..17e98e0 100644
--- a/R/helpers.R
+++ b/R/helpers.R
@@ -35,8 +35,12 @@ make_color_axis_theme <- function(config) {
theme_modify_axes(
axis = if (config$.direction == "horizontal") "x" else "y",
change_color = if (!is.na(config$.color)) config$.color else NULL,
- remove_primary = !is.na(config$.axis_switch) && config$.axis_switch,
- remove_secondary = !is.na(config$.axis_switch) && !config$.axis_switch
+ remove_primary = !is.na(config$.axis_switch) &&
+ ((config$.direction == "horizontal" && !config$.axis_switch) ||
+ (config$.direction == "vertical" && config$.axis_switch)),
+ remove_secondary = !is.na(config$.axis_switch) &&
+ ((config$.direction == "horizontal" && config$.axis_switch) ||
+ (config$.direction == "vertical" && !config$.axis_switch))
) +
# make the shared axis uniform
theme_modify_axes(
@@ -139,7 +143,8 @@ make_plot <- function(config, data, template) {
}
if (config$.direction == "vertical" && is.null(plot$scales$scales[[x_scale_idx]]$limits)) {
# add limits
- plot$scales$scales[[x_scale_idx]]$limits <- limits
+ plot$scales$scales[[x_scale_idx]]$limits <-
+ sort(plot$scales$scales[[x_scale_idx]]$transform(limits))
}
}
@@ -171,7 +176,8 @@ make_plot <- function(config, data, template) {
}
if (config$.direction == "horizontal" && is.null(plot$scales$scales[[y_scale_idx]]$limits)) {
# add limits
- plot$scales$scales[[y_scale_idx]]$limits <- c(config$.shared_axis_min, config$.shared_axis_max)
+ plot$scales$scales[[y_scale_idx]]$limits <-
+ sort(plot$scales$scales[[y_scale_idx]]$transform(limits))
}
}
@@ -411,12 +417,12 @@ calculate_axis_switch <- function(var, alternate, switch, reverse) {
if (!alternate) {
# no alternating axis
return(rep(switch, length(var)))
- } else if (!switch) {
- # alternating axis not switched
- return(var %% 2L == 0L)
- } else {
+ } else if (switch) {
# switched alternating axis
return(var %% 2L == 1L)
+ } else {
+ # alternating axis not switched
+ return(var %% 2L == 0L)
}
}
diff --git a/README.Rmd b/README.Rmd
index 435b7bf..697a7f1 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -100,14 +100,79 @@ dataset$data |>
)
```
-## Show me more
+## What about horizontal stacks?
-```{r economics, fig.height=6, message = FALSE}
+```{r, message = FALSE}
+# download some more data from PANGAEA
+dataset2 <- pangaear::pg_data(doi = "10.1594/PANGAEA.933277")[[1]]
+
+# show what some of these data look like
+dataset2$data[
+ c("Depth sed [m]", "Comp", "δ13C [‰ PDB] (mean, vs. VPDB)")] |>
+ head() |> knitr::kable()
+```
+
+Full citation:
+
+> `r dataset2$citation`
+
+```{r "geodata-horizontal", message = FALSE}
+library(dplyr)
library(ggplot2)
+# provide a different base plot with shared graphics elements among all plots
+my_template <-
+ # it's a ggplot
+ ggplot() +
+ # use a path plot for all (to connect the data points by depth!)
+ geom_point() + geom_path() +
+ # we still want the default stackplot theme
+ theme_stackplot() +
+ # depth is commonly plotted in reverse
+ scale_y_reverse()
+
+# now make the horizontal stack through depth for 2 of the variables
+dataset2$data |>
+ filter(Comp == "C19") |>
+ arrange(`Depth sed [m]`) |>
+ ggstackplot(
+ x = c(
+ "δ13C carb [‰ PDB]",
+ "n-C19 δ13C_org [‰]" = "δ13C [‰ PDB] (mean, vs. VPDB)"
+ ),
+ y = "Depth sed [m]",
+ palette = "Dark2",
+ overlap = 1,
+ template = my_template
+ )
+```
+
+```{r "geodata-horizontal-2", message = FALSE}
+# or show them side by side (note that this could also be achieved with
+# ggplot facets except for the fine-control and coloring of the different x-axes)
+dataset2$data |>
+ filter(Comp == "C19") |>
+ arrange(`Depth sed [m]`) |>
+ ggstackplot(
+ x = c(
+ "δ13C carb [‰ PDB]",
+ "n-C19 δ13C_org [‰]" = "δ13C [‰ PDB] (mean, vs. VPDB)"
+ ),
+ y = "Depth sed [m]",
+ palette = "Dark2",
+ # no more overlap
+ overlap = 0,
+ # fine-tune the axes to be on top and bottom
+ both_axes = TRUE,
+ template = my_template
+ )
+```
-# using the built-in economics dataset in ggplot2 to create a horizontal stack
-# instead of vertical and using many of the customization features available
-# with ggstackplot and ggplot2
+## Show me more
+
+```{r economics, fig.height=6, message = FALSE}
+# using the built-in economics dataset in ggplot2 to create a vertical stacke of
+# double axis plots using many of the customization features available with
+# ggstackplot and ggplot2
ggplot2::economics |>
ggstackplot(
# define shared x axis
@@ -180,4 +245,4 @@ ggplot2::economics |>
## 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 our **[Vignette](https://ggstackplot.kopflab.org/articles/explore.html)** to explore the package further with detailed examples for all the different features
diff --git a/README.md b/README.md
index a06bca9..88dc7b5 100644
--- a/README.md
+++ b/README.md
@@ -111,14 +111,125 @@ dataset$data |>
-## Show me more
+## What about horizontal stacks?
``` r
+# download some more data from PANGAEA
+dataset2 <- pangaear::pg_data(doi = "10.1594/PANGAEA.933277")[[1]]
+
+# show what some of these data look like
+dataset2$data[
+ c("Depth sed [m]", "Comp", "δ13C [‰ PDB] (mean, vs. VPDB)")] |>
+ head() |> knitr::kable()
+```
+
+| Depth sed \[m\] | Comp | δ13C \[‰ PDB\] (mean, vs. VPDB) |
+|----------------:|:----------|--------------------------------:|
+| 120.205 | C17 | -28.185 |
+| 120.205 | phytane | -27.032 |
+| 120.205 | C19 | -28.268 |
+| 120.205 | C21 | -27.901 |
+| 120.205 | C27aaa20R | -29.707 |
+| 120.205 | C28aaa20R | -28.194 |
+
+Full citation:
+
+> Boudinot, F Garrett; Kopf, Sebastian; Dildar, Nadia; Sepúlveda, Julio
+> (2021): Compound-specific carbon isotope results from the SH#1 core
+> analyzed and processed at University of Colorado Boulder \[dataset\].
+> PANGAEA,
+
+``` r
+library(dplyr)
library(ggplot2)
+# provide a different base plot with shared graphics elements among all plots
+my_template <-
+ # it's a ggplot
+ ggplot() +
+ # use a path plot for all (to connect the data points by depth!)
+ geom_point() + geom_path() +
+ # we still want the default stackplot theme
+ theme_stackplot() +
+ # depth is commonly plotted in reverse
+ scale_y_reverse()
-# using the built-in economics dataset in ggplot2 to create a horizontal stack
-# instead of vertical and using many of the customization features available
-# with ggstackplot and ggplot2
+# now make the horizontal stack through depth for 2 of the variables
+dataset2$data |>
+ filter(Comp == "C19") |>
+ arrange(`Depth sed [m]`) |>
+ ggstackplot(
+ x = c(
+ "δ13C carb [‰ PDB]",
+ "n-C19 δ13C_org [‰]" = "δ13C [‰ PDB] (mean, vs. VPDB)"
+ ),
+ y = "Depth sed [m]",
+ palette = "Dark2",
+ overlap = 1,
+ template = my_template
+ )
+#> Warning: There were 4 warnings in `dplyr::mutate()`.
+#> The first warning was:
+#> ℹ In argument: `gtable = map(.data$plot_w_theme, ggplot2::ggplotGrob)`.
+#> Caused by warning:
+#> ! Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_point()`).
+#> ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_point()`).
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_path()`).
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_point()`).
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_path()`).
+```
+
+
+
+``` r
+# or show them side by side (note that this could also be achieved with
+# ggplot facets except for the fine-control and coloring of the different x-axes)
+dataset2$data |>
+ filter(Comp == "C19") |>
+ arrange(`Depth sed [m]`) |>
+ ggstackplot(
+ x = c(
+ "δ13C carb [‰ PDB]",
+ "n-C19 δ13C_org [‰]" = "δ13C [‰ PDB] (mean, vs. VPDB)"
+ ),
+ y = "Depth sed [m]",
+ palette = "Dark2",
+ # no more overlap
+ overlap = 0,
+ # fine-tune the axes to be on top and bottom
+ both_axes = TRUE,
+ template = my_template
+ )
+#> Warning: There were 4 warnings in `dplyr::mutate()`.
+#> The first warning was:
+#> ℹ In argument: `gtable = map(.data$plot_w_theme, ggplot2::ggplotGrob)`.
+#> Caused by warning:
+#> ! Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_point()`).
+#> ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_point()`).
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_path()`).
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_point()`).
+#> Warning: Removed 63 rows containing missing values or values outside the scale range
+#> (`geom_path()`).
+```
+
+
+
+## Show me more
+
+``` r
+# using the built-in economics dataset in ggplot2 to create a vertical stacke of
+# double axis plots using many of the customization features available with
+# ggstackplot and ggplot2
ggplot2::economics |>
ggstackplot(
# define shared x axis
@@ -193,6 +304,7 @@ ggplot2::economics |>
## 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 our
+ **[Vignette](https://ggstackplot.kopflab.org/articles/explore.html)**
+ to explore the package further with detailed examples for all the
+ different features
diff --git a/_pkgdown.yml b/_pkgdown.yml
index b389575..679a85e 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -15,8 +15,8 @@ navbar:
title: ggstackplot
type: default
left:
- - text: Features
- href: articles/features.html
+ - text: Explore
+ href: articles/explore.html
- text: Reference
href: reference/index.html
right:
diff --git a/cran-comments.md b/cran-comments.md
index 397e68a..749ae75 100644
--- a/cran-comments.md
+++ b/cran-comments.md
@@ -1,6 +1,4 @@
-This is a new package.
-
-The reference included in the README acknowledges the example dataset used for demonstrating package functionality but since does not relate to the actual functionality of this package, it is not included in the DESCRIPTION file.
+Update of an existing CRAN package to add a new feature (support of reverse axes) and clarify some of the parameters with additional examples in the package documentation. Details listed in the NEWS.
## Test environments
@@ -12,6 +10,8 @@ The reference included in the README acknowledges the example dataset used for d
## R CMD check results
-0 errors | 0 warnings | 1 note
+0 errors | 0 warnings | 0 notes
+
+## Downstream dependencies
-* This is a new release.
+There are currently no downstream dependencies for this package.
diff --git a/man/figures/README-example-1.png b/man/figures/README-example-1.png
deleted file mode 100644
index 04a7c3c..0000000
Binary files a/man/figures/README-example-1.png and /dev/null differ
diff --git a/man/figures/README-example2-1.png b/man/figures/README-example2-1.png
deleted file mode 100644
index 1ab8386..0000000
Binary files a/man/figures/README-example2-1.png and /dev/null differ
diff --git a/man/figures/README-geodata-horizontal-1.png b/man/figures/README-geodata-horizontal-1.png
new file mode 100644
index 0000000..08c5709
Binary files /dev/null and b/man/figures/README-geodata-horizontal-1.png differ
diff --git a/man/figures/README-geodata-horizontal-2-1.png b/man/figures/README-geodata-horizontal-2-1.png
new file mode 100644
index 0000000..bf8e361
Binary files /dev/null and b/man/figures/README-geodata-horizontal-2-1.png differ
diff --git a/man/ggstackplot-package.Rd b/man/ggstackplot-package.Rd
index 710cc5e..25252a6 100644
--- a/man/ggstackplot-package.Rd
+++ b/man/ggstackplot-package.Rd
@@ -11,13 +11,22 @@ Easily create overlapping grammar of graphics plots for scientific data visualiz
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}}
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 \href{https://ggplot2.tidyverse.org/}{ggplot2} 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 \url{https://ggstackplot.kopflab.org}
+}
+\seealso{
+Useful links:
+\itemize{
+ \item \url{https://ggstackplot.kopflab.org/}
+ \item \url{https://github.com/kopflab/ggstackplot}
+ \item Report bugs at \url{https://github.com/kopflab/ggstackplot/issues}
+}
+
}
\author{
\strong{Maintainer}: Sebastian Kopf \email{sebastian.kopf@colorado.edu} (\href{https://orcid.org/0000-0002-2044-0201}{ORCID}) [copyright holder]
Authors:
\itemize{
- \item Tristan Caro \email{tristan.caro@colorado.edu}
+ \item Tristan Caro \email{tristan.caro@colorado.edu} (\href{https://orcid.org/0000-0001-6177-7444}{ORCID})
\item Jamie McFarlin \email{jamie.mcfarlin@uwyo.edu} (\href{https://orcid.org/0000-0002-8185-8185}{ORCID})
\item Jon Raberg \email{Jonathan.Raberg@colorado.edu} (\href{https://orcid.org/0000-0003-2959-3631}{ORCID})
}
diff --git a/man/ggstackplot.Rd b/man/ggstackplot.Rd
index 4d2a056..aff71ba 100644
--- a/man/ggstackplot.Rd
+++ b/man/ggstackplot.Rd
@@ -64,7 +64,7 @@ assemble_stackplot(
\item{alternate_axes}{whether to alternate the sides on which the stacked axes are plotted}
-\item{switch_axes}{whether to switch the stacked axes. Not switching means the first plot in the lower left corner is always arranged like a regular ggplot with the y axis on the left and the x axis on the bottom (even if \code{alternate_axes = TRUE}). Setting \code{switch_axes = TRUE}, leads to the opposite, i.e. first plot in the lower corner has the variable axis on the other side (secondary in ggplot terms).}
+\item{switch_axes}{whether to switch the stacked axes. Not switching means that for vertical stacks the plot at the bottom has the y-axis always on the left side; and for horizontal stacks that the plot on the left has the x-axis on top. Setting \code{switch_axes = TRUE}, leads to the opposite.}
\item{overlap}{fractional overlap between adjacent plots. The max of 1 means plots are perfectly overlaid. The min of 0 means there is no overlap. If providing multiple values, must be 1 less than the number of stacked plots (since it's describing the overlap/gap between adjacent plots). By default there is no overlap between plots}
@@ -88,7 +88,7 @@ assemble_stackplot(
\code{assemble_stackplot()} returns a ggplot with overlayed plot layers
}
\description{
-Use \code{ggstackplot()} to generate a stackplot. If you need more fine control, use \code{prepare_stackplot()} and \code{assemble_stackplot()} individually.
+Use \code{ggstackplot()} to generate a stackplot. If you need more fine control, use \code{prepare_stackplot()} and \code{assemble_stackplot()} individually. To explore examples of all the different features, check out the \code{vignette("explore", "ggstackplot")} or the \href{https://ggstackplot.kopflab.org/dev/articles/explore.html}{online documentation}.
}
\details{
\code{ggstackplot()} stacks a ggplot template with the provided data and parameters. It returns a plot object generated by \code{\link[cowplot:plot_grid]{cowplot::plot_grid()}}).
@@ -98,7 +98,6 @@ Use \code{ggstackplot()} to generate a stackplot. If you need more fine control,
\code{assemble_stackplot()} is usually not called directly but can be used to manually combine a stackplot tibble (typically created by \code{prepare_stockplot()}). Returns a plot object generated by \code{\link[cowplot:plot_grid]{cowplot::plot_grid()}}).
}
\examples{
-
# 1 step stackplot (most common use)
mtcars |>
ggstackplot(
@@ -117,4 +116,8 @@ mtcars |>
) |>
assemble_stackplot(overlap = c(1, 0, 0.3))
+\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
+# many more examples available in the vignette
+vignette("explore", "ggstackplot")
+\dontshow{\}) # examplesIf}
}
diff --git a/tests/testthat/_snaps/ggstackplot/horizontally-stacked-plot.svg b/tests/testthat/_snaps/ggstackplot/horizontally-stacked-plot.svg
index 583594c..9a352e2 100644
--- a/tests/testthat/_snaps/ggstackplot/horizontally-stacked-plot.svg
+++ b/tests/testthat/_snaps/ggstackplot/horizontally-stacked-plot.svg
@@ -69,18 +69,18 @@
-
-
-
-
-
-
-3.0
-3.5
-4.0
-4.5
-5.0
-drat
+
+
+
+
+
+
+3.0
+3.5
+4.0
+4.5
+5.0
+drat
@@ -132,16 +132,16 @@
-
-
-
-
-
-16
-18
-20
-22
-qsec
+
+
+
+
+
+16
+18
+20
+22
+qsec
@@ -193,16 +193,16 @@
-
-
-
-
-
-2
-3
-4
-5
-wt
+
+
+
+
+
+2
+3
+4
+5
+wt
10
15
diff --git a/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-and-labs-in-template.svg b/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-and-labs-in-template.svg
index 30e6314..5dc4d8d 100644
--- a/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-and-labs-in-template.svg
+++ b/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-and-labs-in-template.svg
@@ -60,18 +60,18 @@
-
-
-
-
-
-
-3.0
-3.5
-4.0
-4.5
-5.0
-x
+
+
+
+
+
+
+3.0
+3.5
+4.0
+4.5
+5.0
+x
@@ -113,16 +113,16 @@
-
-
-
-
-
-16
-18
-20
-22
-x
+
+
+
+
+
+16
+18
+20
+22
+x
10
15
diff --git a/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-in-template.svg b/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-in-template.svg
index f6e0da0..1204eab 100644
--- a/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-in-template.svg
+++ b/tests/testthat/_snaps/ggstackplot/hstack-w-axis-defs-in-template.svg
@@ -60,18 +60,18 @@
-
-
-
-
-
-
-3.0
-3.5
-4.0
-4.5
-5.0
-drat
+
+
+
+
+
+
+3.0
+3.5
+4.0
+4.5
+5.0
+drat
@@ -113,16 +113,16 @@
-
-
-
-
-
-16
-18
-20
-22
-qsec
+
+
+
+
+
+16
+18
+20
+22
+qsec
10
15
diff --git a/tests/testthat/_snaps/ggstackplot/vstack-w-axis-defs-in-template.svg b/tests/testthat/_snaps/ggstackplot/vstack-w-axis-defs-in-template.svg
index 24b4163..91f476c 100644
--- a/tests/testthat/_snaps/ggstackplot/vstack-w-axis-defs-in-template.svg
+++ b/tests/testthat/_snaps/ggstackplot/vstack-w-axis-defs-in-template.svg
@@ -41,22 +41,16 @@
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
@@ -92,23 +86,17 @@
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
@@ -124,18 +112,12 @@
drat
-
-
-
-
-
-
-10
-15
-20
-25
-30
-35
+
+
+
+10
+20
+30
mpg
diff --git a/tests/testthat/test-ggstackplot.R b/tests/testthat/test-ggstackplot.R
index 7eb7d83..5aba7d0 100644
--- a/tests/testthat/test-ggstackplot.R
+++ b/tests/testthat/test-ggstackplot.R
@@ -176,7 +176,7 @@ test_that("test ggstackplot() functionality", {
mtcars, x = mpg, y = c(qsec, drat),
template =
ggplot() + geom_line() +
- scale_x_continuous() +
+ scale_x_log10() +
scale_y_continuous()
)
)
diff --git a/vignettes/features.Rmd b/vignettes/explore.Rmd
similarity index 94%
rename from vignettes/features.Rmd
rename to vignettes/explore.Rmd
index f44d594..77d808e 100644
--- a/vignettes/features.Rmd
+++ b/vignettes/explore.Rmd
@@ -1,8 +1,8 @@
---
-title: "ggstackplot features"
+title: "Explore"
output: rmarkdown::html_vignette
vignette: >
- %\VignetteIndexEntry{ggstackplot features}
+ %\VignetteIndexEntry{explore}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
@@ -19,9 +19,12 @@ knitr::opts_chunk$set(
```
```{r setup}
+# load the package
library(ggstackplot)
```
+This vignette explores the various features of the ggstackplot package.
+
# Main Arguments
## `x` and `y` arguments
@@ -176,7 +179,7 @@ mtcars |>
## `switch_axes` argument
-Determines whether to switch the stacked axes. Not switching means the first plot in the lower left corner is always arranged like a regular ggplot with the y axis on the left and the x axis on the bottom (even if `alternate_axes = TRUE`). Setting `switch_axes = TRUE`}, leads to the opposite, i.e. the first plot in the lower corner has the variable axis on the other side (secondary in ggplot terms). If `alternate_axes = TRUE` this essentially switches the order with which the axes alternate (e.g., right/left/right vs. left/right/left).
+Determines whether to switch the stacked axes. Not switching means that for vertical stacks the plot at the bottom has the y-axis always on the left side; and for horizontal stacks that the plot on the left has the x-axis on top. Setting `switch_axes = TRUE`}, leads to the opposite. If `alternate_axes = TRUE` this essentially switches the order with which the axes alternate (e.g., right/left/right vs. left/right/left). Note that if `both_axes = TRUE`, neither the `switch_axes` nor `alternate_axes` parameter has any effect.
```{r}
# stacked axis starts on the right
@@ -188,7 +191,7 @@ mtcars |>
)
# or for the horizontal version, stacked axis
-# starts on the top
+# starts on the bottom
mtcars |>
ggstackplot(
y = mpg, x = c(wt, qsec),
@@ -475,7 +478,7 @@ mtcars |>
## Axis modifications
-Sometimes secondary axes will still be desired, especially if that axis is a transformation of an existing one. For example, here, we create a square root mpg axis that is plotted against the mpg axis. Again, all of this is defined in the `template` argument by adding a `scale_x_continuous` argument, just as you would in a normal ggplot.
+Sometimes secondary axes will still be desired, especially if that axis is a transformation of an existing one. For example, here, we create a square root mpg axis that is plotted against the mpg axis. All this can also be defined in the `template` argument by adding a `scale_x_continuous` argument, just as you would in a normal ggplot.
```{r}
# add a secondary x axis
@@ -483,8 +486,7 @@ mtcars |>
ggstackplot(
x = mpg, y = c(qsec, drat),
color = c("#E41A1C", "#377EB8"),
- both_axes = TRUE,
- overlap = 0.1,
+ both_axes = TRUE, overlap = 0.1,
template =
ggplot() +
geom_line() +
@@ -502,6 +504,22 @@ mtcars |>
)
```
+Similarly, transformation axes can be introduced such as e.g. a log axis.
+
+```{r}
+mtcars |>
+ ggstackplot(
+ x = mpg, y = c(qsec, drat),
+ color = c("#E41A1C", "#377EB8"),
+ both_axes = TRUE, overlap = 0.1,
+ template =
+ ggplot() +
+ geom_line() +
+ scale_x_log10("this is my log10 mpg axis") +
+ theme_stackplot()
+ )
+```
+
## Additional aesthetics
Aesthetics are also defined in the `template` argument. Remember, the only parameters that are defined in the stackplot are (i) the shared axis (in this case, `mpg` ), (ii) the axes to be stacked, in this case `y = c(wt, qsec, drat)`, (iii) any ggstackplot-specific arguments. All ggplot arguments and aesthetics are assigned in the `template` argument.