Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5f2684
commit 7128f03
Showing
18 changed files
with
540 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
YEAR: 2022 | ||
YEAR: 2024 | ||
COPYRIGHT HOLDER: Kyla Belisario |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.