Skip to content

Commit

Permalink
version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyla Belisario authored and cran-robot committed Apr 8, 2024
1 parent a5f2684 commit 7128f03
Show file tree
Hide file tree
Showing 18 changed files with 540 additions and 367 deletions.
13 changes: 8 additions & 5 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: ggcorset
Type: Package
Title: The Corset Plot
Version: 0.4.5
Version: 0.5.0
Author: Kyla Belisario
Maintainer: Kyla Belisario <kyla_belisario@protonmail.com>
Description: Corset plots are a visualization technique used strictly to visualize repeat measures
Expand All @@ -13,14 +13,17 @@ Description: Corset plots are a visualization technique used strictly to visuali
integration so that users can customize their visualizations as required. Users can create corset
plots using data in either wide or long format using the functions gg_corset() or gg_corset_elongated(), respectively.
License: MIT + file LICENSE
URL: https://cran.r-project.org/package=ggcorset,
https://github.com/kbelisar/ggcorset
BugReports: https://github.com/kbelisar/ggcorset/issues
Depends: R (>= 3.5.0)
Imports: ggplot2, dplyr, gghalves, ggstance
Imports: ggplot2, gghalves
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
Suggests: rmarkdown, knitr, viridis, MetBrewer
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2022-12-11 20:03:15 UTC; kyla
Packaged: 2024-04-07 12:39:39 UTC; kyla
Repository: CRAN
Date/Publication: 2022-12-11 22:20:03 UTC
Date/Publication: 2024-04-07 13:33:01 UTC
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,2 +1,2 @@
YEAR: 2022
YEAR: 2024
COPYRIGHT HOLDER: Kyla Belisario
27 changes: 17 additions & 10 deletions MD5
@@ -1,17 +1,24 @@
8f8f8b0a1cd561a653281a103406f374 *DESCRIPTION
1fcfae4844cb568b775335b275609d11 *LICENSE
a406bc588db87dfbba630968849ab089 *NAMESPACE
8cb469a466b45d9f7e1b6580e0488579 *DESCRIPTION
672f685c5daca7f6746577c64bc13f5c *LICENSE
489b593d868009d26a569651eed4048f *NAMESPACE
9753e382e198a937b1f0e8bff825edbd *R/drinkdays.R
096ca5ef36c67c3251311a49a54d18af *R/gg_corset.R
8240cf1377d16caf9463be81763509db *R/gg_corset_elongated.R
a97921e44510b1d57ce85d292ffb09ed *R/utils.R
dc68d114330f4a706ba9a93b44f5d7ce *build/vignette.rds
cd6f40e5ba3beefc4533d08ca4c83c80 *R/gg_corset.R
3c8868d82d93df553606d9a97700e118 *R/gg_corset_elongated.R
4f98e6786aa23461491d09d250bf8993 *R/position_dodgev.R
7b4e2dcc8d465e92a33eeb2fba87894a *R/utils.R
ef47a0f3c02fc091f3c418aef6370d96 *build/vignette.rds
7203565e8cdf031b0129f2ab67255c27 *data/drinkdays.RData
3e976817af1a71729b893234d2a9d7dd *inst/CITATION
79e7dd20ecd6bd22e10d592d87ebc73b *inst/doc/corset_plot_intro.R
be9049924c48578256ff4184d715046c *inst/doc/corset_plot_intro.Rmd
799dd20c16b5caca68fc622a2ec4c5c5 *inst/doc/corset_plot_intro.html
81353cf77999c6b16b529677195d936e *inst/doc/corset_plot_intro.html
026e24a42ca777d27938d48aba91a424 *man/drinkdays.Rd
811316312af04ce91a78735f271b6d73 *man/gg_corset.Rd
4fc75a80a25e8e4803926f05037bbae3 *man/gg_corset_elongated.Rd
02e66264842faf6ae5f77eb1559d5af3 *man/gg_corset.Rd
aa9f3f2bc3ea54884478d48ddd341ecf *man/gg_corset_elongated.Rd
4c23ad4bf155fea3c3f1cc268fd9abd7 *man/theme_ggcorset.Rd
be9049924c48578256ff4184d715046c *vignettes/corset_plot_intro.Rmd
6bf4ef1932e9bc7f838a534f80d31c6a *vignettes/img/example_corset_plot_age.png
374cef61cc0c6a4687f0cebe310d98cf *vignettes/img/example_corset_plot_anatomy.png
cf31710c21e2d18d8201c8ba57733d11 *vignettes/img/example_corset_plot_github_eyelets.png
60edaf15bb75116badbe2685e26e4938 *vignettes/img/example_corset_plot_github_faceted.png
0e8adbff3db6eefb6938532c4e6a9305 *vignettes/img/example_corset_plot_latentclass.png
7 changes: 1 addition & 6 deletions NAMESPACE
Expand Up @@ -3,11 +3,6 @@
export(gg_corset)
export(gg_corset_elongated)
export(theme_ggcorset)
importFrom(dplyr,"%>%")
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,select)
importFrom(dplyr,summarize)
importFrom(gghalves,geom_half_violin)
importFrom(ggplot2,"%+replace%")
importFrom(ggplot2,aes)
Expand All @@ -26,6 +21,6 @@ importFrom(ggplot2,position_nudge)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(ggplot2,unit)
importFrom(ggstance,position_dodgev)
importFrom(stats,reshape)
importFrom(stats,sd)
importFrom(stats,var)
275 changes: 142 additions & 133 deletions R/gg_corset.R

Large diffs are not rendered by default.

272 changes: 142 additions & 130 deletions R/gg_corset_elongated.R

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions R/position_dodgev.R
@@ -0,0 +1,119 @@
### The following code for vertical dodging in ggplot (position_dodgev) is adapted from Lionel Henry's ggstance package
### as it will be archived on CRAN in 2024 [https://github.com/lionel-/ggstance]
### Edits include removing unused arguments; combining functions; and removing the use of the plyr::ddply function

pos_dodgev <- function(df, height) {

n <- length(unique(df$group))

if (!all(c("ymin", "ymax") %in% names(df))) {
df$ymin <- df$y
df$ymax <- df$y
}

d_height <- max(df$ymax - df$ymin)

# Have a new group index from 1 to number of groups.
# This might be needed if the group numbers in this set don't include all of 1:n
groupidy <- match(df$group, sort(unique(df$group)))

# Find the center for each group, then use that to calculate ymin and ymax
df$y <- df$y + height * ((groupidy - 0.5) / n - .5)
df$ymin <- df$y - d_height / n / 2
df$ymax <- df$y + d_height / n / 2

return(df)
}

#' @inheritParams ggplot2::position_dodge

collidev <- function(data, height = NULL, name, strategy) {

# Determine height
if (!is.null(height)) {
# Width set manually
if (!(all(c("ymin", "ymax") %in% names(data)))) {
data$ymin <- data$y - height / 2
data$ymax <- data$y + height / 2
}
} else {
if (!(all(c("ymin", "ymax") %in% names(data)))) {
data$ymin <- data$y
data$ymax <- data$y
}

# Width determined from data, must be floating point constant
heights <- unique(data$ymax - data$ymin)
heights <- heights[!is.na(heights)]
height <- heights[1]
}

# Reorder by x position, then on group
data <- data[order(data$ymin, data$group), ]

# Check for overlap
intervals <- as.numeric(t(unique(data[c("ymin", "ymax")])))
intervals <- intervals[!is.na(intervals)]

if (!is.null(data$xmax)) {
data <- pos_dodgev(data,height)
} else if (!is.null(data$x)) {
data$xmax <- data$x
data <- pos_dodgev(data,height)
data$x <- data$xmax
return(data)
} else {
stop("Neither x nor xmax defined")
}
}

#' @format NULL
#' @usage NULL

PositionDodgev <- ggplot2::ggproto("PositionDodgev", ggplot2::Position,
height = NULL, preserve = "total",
setup_params = function(self, data) {
if (is.null(data$ymin) && is.null(data$ymax) && is.null(self$height)) {
warning("Height not defined. Set with `position_dodge(height = ?)`",
call. = FALSE)
}

if (identical(self$preserve, "total")) {
n <- NULL
} else {
panels <- unname(split(data, data$PANEL))
ns <- vapply(panels, function(panel) max(table(panel$ymin)), double(1))
n <- max(ns)
}

list(
height = self$height,
n = n
)
},

setup_data = function(self, data, params) {
if (!"y" %in% names(data) && all(c("ymin", "ymax") %in% names(data))) {
data$y <- (data$ymin + data$ymax) / 2
}
data
},

compute_panel = function(data, params, scales) {
collidev(
data,
params$height,
name = "position_dodgev")
}
)


#' POSITION DODGE-V
#' @name position_dodgev
#' @noRd

position_dodgev <- function(height = NULL) {
ggplot2::ggproto(NULL, PositionDodgev,
height = height
)
}
9 changes: 9 additions & 0 deletions R/utils.R
Expand Up @@ -38,3 +38,12 @@ theme_ggcorset <- function() {
axis.ticks = element_line(size = 0.75),
strip.text = element_text(size = 13, face = "bold", vjust = 0.5, margin = margin(t = 5, b = 5)))
}

#' `se()`
#' This function calculates standard error.
#' @name se
#' @param x An R object.
#' @noRd

se <- function(x){sqrt(var(x[!is.na(x)])/length(x[!is.na(x)]))}

Binary file modified build/vignette.rds
Binary file not shown.
9 changes: 9 additions & 0 deletions inst/CITATION
@@ -0,0 +1,9 @@
bibentry(
bibtype = "Manual",
header = "To cite ggcorset in publications, please use the following:",
author = "Kyla Belisario",
title = "Corset Plots: Visualizing Heterogeneity in Change Outcomes Across Two Timepoints",
year = "2021",
doi = "10.5281/zenodo.4905031",
url = "https://cran.r-project.org/package=ggcorset"
)
140 changes: 70 additions & 70 deletions inst/doc/corset_plot_intro.html

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions man/gg_corset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions man/gg_corset_elongated.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added vignettes/img/example_corset_plot_age.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/img/example_corset_plot_anatomy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7128f03

Please sign in to comment.