Skip to content

Commit 1500865

Browse files
maraab23cran-robot
authored andcommitted
version 0.7.2
1 parent 209a7ab commit 1500865

23 files changed

+424
-296
lines changed

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ggseqplot
22
Title: Render Sequence Plots using 'ggplot2'
3-
Version: 0.6.2
3+
Version: 0.7.2
44
Authors@R:
55
person("Marcel", "Raab", , "marcel.raab@gmail.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-3097-1591"))
@@ -13,9 +13,10 @@ Description: A set of wrapper functions that mainly re-produces some of the
1313
can be added and tweaked using '+' and regular 'ggplot2' functions.
1414
URL: https://github.com/maraab23/ggseqplot
1515
BugReports: https://github.com/maraab23/ggseqplot/issues
16+
Depends: R (>= 4.1.0)
1617
License: GPL (>= 3)
1718
Encoding: UTF-8
18-
RoxygenNote: 7.2.0
19+
RoxygenNote: 7.2.1
1920
RdMacros: Rdpack
2021
Imports: colorspace, dplyr, forcats, ggh4x, ggplot2, ggrepel, ggtext,
2122
glue, patchwork, purrr, Rdpack, tidyr, TraMineR, usethis
@@ -24,8 +25,8 @@ Suggests: covr, ggthemes, hrbrthemes, knitr, rmarkdown, testthat (>=
2425
VignetteBuilder: knitr
2526
Config/testthat/edition: 3
2627
NeedsCompilation: no
27-
Packaged: 2022-07-04 11:44:24 UTC; ba3gh6
28+
Packaged: 2022-08-05 19:04:29 UTC; ba3gh6
2829
Author: Marcel Raab [aut, cre] (<https://orcid.org/0000-0002-3097-1591>)
2930
Maintainer: Marcel Raab <marcel.raab@gmail.com>
3031
Repository: CRAN
31-
Date/Publication: 2022-07-04 18:50:01 UTC
32+
Date/Publication: 2022-08-05 23:20:02 UTC

MD5

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
e0296f8a972ee8589dff2dd42094cb05 *DESCRIPTION
1+
fbaeb84e4dfcb3d3eb8fe99cabea3cf1 *DESCRIPTION
22
361e3275082f87d354ce9f73a1c9b19c *NAMESPACE
3-
6736182eaa7b27a253f44404f1e81d28 *NEWS.md
4-
2134e28b158f1a511f1f257de7361069 *R/ggseqdplot.R
5-
8d8a22b1dfa6a98c0d5fc77b32239b00 *R/ggseqeplot.R
6-
dcbb2e18c845766fb645b5197e46f32a *R/ggseqfplot.R
7-
342607c757f495542513a177d53cbd92 *R/ggseqiplot.R
8-
8313bf84e8d5f4e1dc09a87dafa85f0a *R/ggseqmsplot.R
9-
d179b5a2d0a2fe1fe88a4edd5641a198 *R/ggseqmtplot.R
3+
042fe86cf01387b295cbd54caaad87da *NEWS.md
4+
baefc51effdc621d0d16d7f9373dd04a *R/ggseqdplot.R
5+
29bd8a25ae16d32475bc0f34d9910152 *R/ggseqeplot.R
6+
5e888a4b9be96f332b5e9f3d7c2c5472 *R/ggseqfplot.R
7+
0480af3fa441898cb2d7a8fc9fe6c4c1 *R/ggseqiplot.R
8+
04dd849a50c3e61ac1a3243ad658bddf *R/ggseqmsplot.R
9+
ac08285586cfc7d245a375a998c9c334 *R/ggseqmtplot.R
1010
b4fe12876c37f8a22cde06e9701eecf0 *R/ggseqplot-package.R
11-
b4fe12876c37f8a22cde06e9701eecf0 *R/ggseqplot.R
12-
bcbd0fe8de982eb18f7d481c7e57e568 *R/ggseqrfplot.R
13-
eb3137aa088cdc1a61cbd39605a40794 *R/ggseqrplot.R
11+
3d5c2c4ff2d4c2a88d05b26ae594d3b1 *R/ggseqrfplot.R
12+
602ee9a1a3d5f75adfc9bcc4b11bfd5b *R/ggseqrplot.R
1413
dcee99c9256d2e4414d976a0daaf4de1 *R/ggseqtrplot.R
1514
1258fea7e8d2ca58c93013f3457a6426 *R/internal_helpers.R
1615
1e0513eb832ab85041b19d30cded2794 *R/rfplot.R
17-
436e07fd09c8b659e3c8a121959590ce *README.md
18-
3dabbb19239dc81f3861d8c490904833 *build/partial.rdb
16+
7bc6b0ed9ad9d94b0a255c2ca22999f8 *README.md
17+
c6cb2824f89d408c48dac55dd86175a1 *build/partial.rdb
1918
3f4888d915d1e61bd3e4b47e46f5794b *build/vignette.rds
2019
d975bd9930cfa30644934bb7359e30ba *inst/REFERENCES.bib
21-
449a8766f2365da12d3cf5689020cba8 *inst/doc/ggseqplot.R
22-
469282c3e6d8c75704eb46f7fa1639d7 *inst/doc/ggseqplot.Rmd
23-
aeba60eb851fb7f98853962549b11fc4 *inst/doc/ggseqplot.html
20+
4d639a0591394ca7862dcf5b0a68c098 *inst/doc/ggseqplot.R
21+
b3bcbcd5bbe7f0f360ebd5492d063eeb *inst/doc/ggseqplot.Rmd
22+
22e72bd9b607011dd02ce05caa6e19f2 *inst/doc/ggseqplot.html
2423
441fb46be1612086d7ea49567c01fa0f *man/figures/README-ggseqdplot1-1.png
2524
fa6ecb6406f222a8c7f18832fda9ac59 *man/figures/README-ggseqdplot2-1.png
2625
2b4ccbde4e94508ecb42516330971d2d *man/figures/README-ggseqeplot1-1.png
@@ -36,18 +35,18 @@ e4bdee6ea6dc7db8b9c8e58043b8e5bc *man/figures/README-seqiplot2-1.png
3635
e4110e018e5be64b02a72c36eaad72c5 *man/figures/README-seqiplot3-1.png
3736
0e555a91e15ff18516b7f9bf2410f950 *man/figures/README-seqplot.rf1-1.png
3837
d4852713e6dd16952596233d7cb79262 *man/figures/logo.png
39-
6e28eacf5deb7de8128d25f51be97c9c *man/ggseqdplot.Rd
38+
f990fb4c87a8c12e8a3bac069c06af45 *man/ggseqdplot.Rd
4039
5384f8fda4d05813ad1fb5bb44090e0e *man/ggseqeplot.Rd
4140
be53f203ce28559b2fc6d99dfecb3863 *man/ggseqfplot.Rd
42-
70a290828c501f915f1a9195381bb1e9 *man/ggseqiplot.Rd
41+
1b00cb2c5d9c9ef8bd688407370e4036 *man/ggseqiplot.Rd
4342
15a2a5a1bc2a345b41ef17bfd64e146d *man/ggseqmsplot.Rd
44-
700819262ac4b48cfa07a8914e0d1ab3 *man/ggseqmtplot.Rd
45-
00b9d46b3606af31eafd99901dd9cc81 *man/ggseqplot-package.Rd
43+
3292bbdc8b79664303a179ac7a9314e0 *man/ggseqmtplot.Rd
44+
5fe5d56f65d3e4c1447b3b6c3982c90b *man/ggseqplot-package.Rd
4645
4218f28187142aec59f98d0a0aeecb30 *man/ggseqrfplot.Rd
4746
348219434df2cd9fe733c7f3eb9e6bb4 *man/ggseqrplot.Rd
4847
4438909bd0c1d8376fe6b8c9fd5a1478 *man/ggseqtrplot.Rd
4948
3bc2a687a7d1df2f3288d53ad3b62a9e *tests/testthat.R
50-
410a689f181635f0ca4267d5f4bfa1c4 *tests/testthat/test-ggseqdplot.R
49+
a2ca54f7006828ba3c3c7023d3f1cc62 *tests/testthat/test-ggseqdplot.R
5150
14de6f52b3b53f6ed44d40cd8e433281 *tests/testthat/test-ggseqeplot.R
5251
850024320023f17b021777ff9439f62f *tests/testthat/test-ggseqfplot.R
5352
100bd1b3e41e5b96e24404f541a666c1 *tests/testthat/test-ggseqiplot.R
@@ -58,5 +57,5 @@ e160b0a4ee91add24d54b7d714a940c1 *tests/testthat/test-ggseqrplot.R
5857
7c043c3cd3ac04ec0bed66df5819cea9 *tests/testthat/test-ggseqtrplot.R
5958
a4b5f30fd19f2de28f0cd30c893efbf2 *tests/testthat/test-internal_helper.R
6059
d583298e6b05f76766685b9557b7808d *tests/testthat/test-rfplot.R
61-
469282c3e6d8c75704eb46f7fa1639d7 *vignettes/ggseqplot.Rmd
60+
b3bcbcd5bbe7f0f360ebd5492d063eeb *vignettes/ggseqplot.Rmd
6261
f5dd7b005604e4fad4ba0d642598e54c *vignettes/references.bib

NEWS.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
# ggseqplot 0.6.2
2-
3-
* Added a `NEWS.md` file to track changes to the package.
1+
# ggseqplot 0.7.2
2+
3+
* fixed sorting issue for y-axis labels in grouped iplots
4+
* allow for additional facet_wrap arguments to change plot appearance
5+
6+
# ggseqplot 0.7.1
7+
8+
* Tweaking the theme: adding ticks and x axis line
9+
10+
# ggseqplot 0.7.0
11+
12+
* Added option to break down dplots by state (`dissect`)
13+
14+
# ggseqplot 0.6.2.9000 <br><small>(development version)</small>
15+
16+
* Set minimum R version because of R's new pipe (#1, @cbrueffer)
17+
18+
# ggseqplot 0.6.2
19+
20+
* Added a `NEWS.md` file to track changes to the package.

R/ggseqdplot.R

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
#'
88
#' @eval shared_params()
99
#' @param no.n specifies if number of (weighted) sequences is shown (default is \code{TRUE})
10+
#' @param dissect if \code{"row"} or \code{"col"} are specified separate distribution plots instead of a stacked plot are displayed;
11+
#' \code{"row"} and \code{"col"} display the distributions in one row or one column respectively; default is \code{NULL}
1012
#' @param with.missing Specifies if missing states should be considered when computing the state distributions (default is \code{FALSE}).
1113
#' @param border if \code{TRUE} bars are plotted with black outline; default is \code{FALSE} (also accepts \code{NULL})
1214
#' @param with.entropy add line plot of cross-sectional entropies at each sequence position
1315
#' @param linetype The linetype for the entropy subplot (\code{with.entropy==TRUE}) can be specified with an integer (0-6) or name (0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash); ; default is \code{"dashed"}
1416
#' @param linecolor Specifies the color of the entropy line if \code{with.entropy==TRUE}; default is \code{"black"}
1517
#' @param linewidth Specifies the width of the entropy line if \code{with.entropy==TRUE}; default is \code{1}
1618
#' @eval shared_facet()
19+
#' @param ... if group is specified additional arguments of \code{\link[ggplot2:facet_wrap]{ggplot2::facet_wrap}}
20+
#' such as \code{"labeller"} or \code{"strip.position"} can be used to change the appearance of the plot. Does
21+
#' not work if \code{dissect} is used
1722
#'
1823
#' @return A sequence distribution plot created by using \code{\link[ggplot2]{ggplot2}}.
1924
#' If stored as object the resulting list object (of class gg and ggplot) also
@@ -27,11 +32,12 @@
2732
#' decades (see \insertCite{blossfeld1987;textual}{ggseqplot} for an early application),
2833
#' it should be noted that the size of the different bars in stacked bar charts
2934
#' might be difficult to compare - particularly if the alphabet comprises many
30-
#' states \insertCite{wilke2019}{ggseqplot}. Moreover, it is important to keep
31-
#' in mind that this plot type does not visualize individual trajectories;
32-
#' instead it displays aggregated distributional information (repeated cross-sections).
33-
#' For a more detailed discussion of this type of sequence visualization see,
34-
#' for example, \insertCite{brzinsky-fay2014;textual}{ggseqplot},
35+
#' states \insertCite{wilke2019}{ggseqplot}. This issue can be addressed by breaking down
36+
#' the aggregated distribution specifying the \code{dissect} argument. Moreover, it
37+
#' is important to keep in mind that this plot type does not visualize individual
38+
#' trajectories; instead it displays aggregated distributional information
39+
#' (repeated cross-sections). For a more detailed discussion of this type of
40+
#' sequence visualization see, for example, \insertCite{brzinsky-fay2014;textual}{ggseqplot},
3541
#' \insertCite{fasang2014;textual}{ggseqplot}, and \insertCite{raab2022;textual}{ggseqplot}.
3642
#'
3743
#' The function uses \code{\link[TraMineR:seqstatd]{TraMineR::seqstatd}} to obtain state
@@ -40,8 +46,12 @@
4046
#' the \code{\link[TraMineR:seqdef]{TraMineR::seqdef}} function. The state distributions
4147
#' are reshaped into a a long data format to enable plotting with \code{\link[ggplot2]{ggplot2}}.
4248
#' The stacked bars are rendered by calling \code{\link[ggplot2]{geom_bar}}; if \code{entropy = TRUE}
43-
#' entropy values are plotted with \code{\link[ggplot2]{geom_line}}. The data
44-
#' and specifications used for rendering the plot can be obtained by storing the
49+
#' entropy values are plotted with \code{\link[ggplot2]{geom_line}}. If the \code{group} or the
50+
#' \code{dissect} argument are specified the sub-plots are produced by using
51+
#' \code{\link[ggplot2]{facet_wrap}}. If both are specified the plots are rendered with
52+
#' \code{\link[ggplot2]{facet_grid}}.
53+
#'
54+
#' The data and specifications used for rendering the plot can be obtained by storing the
4555
#' plot as an object. The appearance of the plot can be adjusted just like with
4656
#' every other ggplot (e.g., by changing the theme or the scale using \code{+} and
4757
#' the respective functions).
@@ -84,6 +94,9 @@
8494
#' ggseqdplot(actcal.seq, group = actcal$sex,
8595
#' no.n = TRUE, with.entropy = TRUE, border = TRUE)
8696
#'
97+
#' # break down the stacked plot to ease comparisons of distributions
98+
#' ggseqdplot(actcal.seq, group = actcal$sex, dissect = "row")
99+
#'
87100
#' # make use of ggplot functions for modifying the plot
88101
#' ggseqdplot(actcal.seq) +
89102
#' scale_x_discrete(labels = month.abb) +
@@ -98,6 +111,7 @@
98111
ggseqdplot <- function(seqdata,
99112
no.n = FALSE,
100113
group = NULL,
114+
dissect = NULL,
101115
weighted = TRUE,
102116
with.missing = FALSE,
103117
border = FALSE,
@@ -106,11 +120,18 @@ ggseqdplot <- function(seqdata,
106120
linecolor = "black",
107121
linewidth = 1,
108122
facet_ncol = NULL,
109-
facet_nrow = NULL) {
123+
facet_nrow = NULL,
124+
...) {
110125
if (!inherits(seqdata, "stslist")) {
111126
stop("data are not stored as sequence object, use 'TraMineR::seqdef' to create one")
112127
}
113128

129+
if (!is.null(dissect) & with.entropy == TRUE) {
130+
usethis::ui_warn(glue::glue('
131+
You tried to render a disaggregated dplot using `dissect`, while also setting `with.entropy` to `TRUE`.
132+
As the state-specific distrubution plots would repeatedly show the same entropy line, `with.entropy = TRUE` is ignored.'))
133+
with.entropy <- FALSE
134+
}
114135

115136
if (!is.null(group) & (length(group) != nrow(seqdata))) {
116137
stop("length of group vector must match number of rows of seqdata")
@@ -260,7 +281,7 @@ ggseqdplot <- function(seqdata,
260281

261282
ggdplot <- ggdplot +
262283
scale_fill_manual(values = cpal) +
263-
scale_y_continuous(expand = expansion(add = c(.01, 0))) +
284+
scale_y_continuous(expand = expansion(add = 0)) +
264285
scale_x_discrete(
265286
expand = expansion(add = .15),
266287
breaks = kbreaks,
@@ -272,6 +293,8 @@ ggseqdplot <- function(seqdata,
272293
theme_minimal() +
273294
theme(
274295
axis.title.y = element_text(vjust = +3),
296+
axis.line.x = element_line(size = .3),
297+
axis.ticks = element_line(size = .3),
275298
legend.position = "bottom",
276299
legend.title = element_blank(),
277300
legend.margin = margin(-0.2, 0, 0, -0.2, unit = "cm")
@@ -285,7 +308,8 @@ ggseqdplot <- function(seqdata,
285308
facet_wrap(~ .data$grouplab,
286309
scales = "free_y",
287310
ncol = facet_ncol,
288-
nrow = facet_nrow
311+
nrow = facet_nrow,
312+
...
289313
) +
290314
labs(x = "", y = "Rel. Freq.") +
291315
theme(panel.spacing = unit(2, "lines"),
@@ -301,6 +325,36 @@ ggseqdplot <- function(seqdata,
301325
}
302326

303327

328+
if (grsize == 1 & !is.null(dissect)) {
329+
suppressMessages(
330+
ggdplot <- ggdplot +
331+
{if(dissect == "row")facet_wrap(~rev(.data$state), nrow = 1)} +
332+
{if(dissect == "col")facet_wrap(~rev(.data$state), ncol = 1)} +
333+
scale_y_continuous(limits = c(0,1)) +
334+
theme(panel.grid.major.x = element_blank(),
335+
panel.grid.minor = element_blank(),
336+
panel.spacing = unit(2, "lines"),
337+
strip.text = element_blank())
338+
)
339+
}
340+
341+
342+
if (grsize > 1 & !is.null(dissect)) {
343+
suppressMessages(
344+
ggdplot <- ggdplot +
345+
{if(dissect == "row")facet_grid(vars(.data$grouplab), vars(rev(.data$state)), switch = "y")} +
346+
{if(dissect == "col")facet_grid(vars(.data$state), vars(.data$grouplab), switch = "y")} +
347+
scale_y_continuous(limits = c(0,1)) +
348+
theme(panel.grid.major.x = element_blank(),
349+
panel.grid.minor = element_blank(),
350+
panel.spacing = unit(2, "lines"),
351+
strip.placement = "outside") +
352+
{if(dissect == "col")theme(strip.text.y = element_blank())} +
353+
{if(dissect == "row")theme(strip.text.x = element_blank())}
354+
)
355+
}
356+
357+
304358
ggdplot <- ggdplot +
305359
theme(plot.margin = margin(15, 15, 10, 15))
306360

0 commit comments

Comments
 (0)