Skip to content

Commit 3443393

Browse files
committed
v0.3.0 added additional options for letter aesthetics
1 parent fbe4923 commit 3443393

File tree

8 files changed

+57
-18
lines changed

8 files changed

+57
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ggtukey
22
Title: Compact Letter Displays for 'ggplot2'
3-
Version: 0.2.0
3+
Version: 0.3.0
44
Authors@R:
55
person("Ethan", "Bass", , "ethanbass@gmail.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-6175-6739"))

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# ggtukey 0.3.0 dev
2+
3+
* Added additional parameters to `geom_tukey` (`geom`, `color`, `fill,` & `alpha`) for further customization of letters.
4+
15
# ggtukey 0.2.0
26

37
* Added additional options to `where` parameter for placement of letters.

R/boxplot_letters.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ boxplot_letters <- function(data, x, y, fill, group, test = c("tukey", "kruskalm
8989
geom_box <- purrr::partial(geom_boxplot, color = "black", fill = {{fill}})
9090
}
9191

92-
p <- data %>% #Dataframe from which data will be drawn
92+
p <- data %>% # Dataframe from which data will be drawn
9393
ggplot(aes(x = {{x}}, y = {{y}})) +
9494
geom_box() +
9595
theme_article() + #Clean, minimal theme courtesy of the "egg" package
@@ -117,7 +117,7 @@ boxplot_letters <- function(data, x, y, fill, group, test = c("tukey", "kruskalm
117117
}
118118
}
119119
if (!missing(group)){
120-
p <- p <- p + facet_wrap(vars({{group}}))
120+
p <- p + facet_wrap(vars({{group}}))
121121
}
122122
p + geom_tukey(test = test, type = type, where = where,
123123
hjust = hjust, vjust = vjust, size = lab_size,

R/geom_tukey.R

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
#' @param type If a grouping variable is provided, determines whether to run
66
#' separate tests for each facet (\code{one-way}) or one (\code{two-way}) test with
77
#' an interaction term between \code{x} and \code{group}. Defaults to \code{two-way}.
8+
#' @param threshold Statistical threshold for significance. Defaults to 0.05.
89
#' @param where Where to put the letters. Either above the box (\code{box}) or
910
#' upper whisker (\code{whisker}) of a boxplot; at the \code{mean} or
1011
#' \code{median}; or at the top of the error bars calculated from the standard
1112
#' error (\code{se}), standard deviation \code{sd}, or 95% confidence intervals
1213
#' returned by \code{\link[Hmisc]{smean.cl.normal}}, or \code{\link[Hmisc]{smean.cl.boot}}.
1314
#' @param hjust Horizontal adjustment of the label. (Argument to \code{\link[ggplot2]{geom_text}}).
1415
#' @param vjust Vertical adjustment of the label. (Argument to \code{\link[ggplot2]{geom_text}}).
16+
#' @param geom Which geom to use to plot letters. Options are \code{text} and \code{label}.
1517
#' @param size Label size. Argument to \code{\link[ggplot2]{geom_text}}.
18+
#' @param color Label color.
19+
#' @param fill Label fill (only applies if \code{geom == "label"}).
20+
#' @param alpha Label transparency. Defaults to 1.
1621
#' @param na.rm Logical. Whether to remove observations with NAs for the provided
1722
#' factors (i.e. \code{x} and \code{group}) before plotting. Defaults to TRUE.
18-
#' @param threshold Statistical threshold for significance. Defaults to 0.05.
1923
#' @author Ethan Bass
2024
#' @references
2125
#' * Piepho, Hans-Peter. An Algorithm for a Letter-Based Representation of
@@ -43,11 +47,13 @@
4347
#' data |> ggplot(aes(x=Size, y=Value)) + geom_boxplot() + facet_wrap(~Category) + geom_tukey()
4448
#' @export
4549

46-
geom_tukey <- function(test = c("tukey","kruskalmc"), threshold = 0.05,
47-
type=c("two-way", "one-way"),
50+
geom_tukey <- function(test = c("tukey","kruskalmc"),
51+
type=c("two-way", "one-way"), threshold = 0.05,
4852
where = c("box","whisker", "mean", "median", "se", "sd",
4953
"cl_normal", "cl_boot"),
50-
hjust = 0, vjust = -0.2, size = 4, na.rm = TRUE){
54+
hjust = 0, vjust = -0.2, geom="text",
55+
size = 4, color="black", fill="white",
56+
alpha = 1, na.rm = TRUE){
5157
# store inputs in classed output that can
5258
# be passed to a `ggplot_add` method
5359
test <- match.arg(test, c("tukey", "kruskalmc"))
@@ -71,7 +77,11 @@ geom_tukey <- function(test = c("tukey","kruskalmc"), threshold = 0.05,
7177
vjust = vjust,
7278
size = size,
7379
na.rm = na.rm,
74-
threshold = threshold
80+
threshold = threshold,
81+
color = color,
82+
geom=geom,
83+
alpha=alpha,
84+
fill=fill
7585
)
7686
}
7787

@@ -80,7 +90,8 @@ geom_tukey <- function(test = c("tukey","kruskalmc"), threshold = 0.05,
8090
geom_tukey_ <- function(p, test = c("tukey","kruskalmc"), threshold = 0.05,
8191
type=c("two-way", "one-way"),
8292
where = c("box","whisker", "mean","median", "se", "sd","cl_normal","cl_boot"),
83-
hjust = 0, vjust = 0, size = 4, na.rm = TRUE) {
93+
hjust = 0, vjust = 0, size = 4, geom="text",
94+
color="black", fill="white", alpha=1, na.rm = TRUE) {
8495
data <- p$data
8596
if (na.rm){
8697
data <- drop_na(data, !!p$mapping$x, !!p$facet$params$facets[[1]])
@@ -104,9 +115,18 @@ geom_tukey_ <- function(p, test = c("tukey","kruskalmc"), threshold = 0.05,
104115
threshold = threshold)
105116
}
106117
}
107-
geom_text(data = data,
108-
aes(y = .data$Placement.Value, label = .data$Letter), hjust = hjust,
109-
vjust = vjust, size = size)
118+
if (geom =="text"){
119+
geom_text(data = data,
120+
aes(y = .data$Placement.Value, label = .data$Letter), hjust = hjust,
121+
vjust = vjust, size = size, color=color, alpha=alpha)
122+
} else if (geom == "label"){
123+
geom_label(data = data,
124+
aes(y = .data$Placement.Value, label = .data$Letter), hjust = hjust,
125+
vjust = vjust, size = size, color=color, alpha=alpha,
126+
label.size = 0, fill=fill)
127+
}
128+
129+
110130
}
111131

112132
#' @name ggplot_add.geom_tukey

R/utils.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ get_tukey_letters <- function(data, x, y, group = NULL, test = c("tukey", "krusk
2424
where <- match.arg(where, c("box", "whisker", "mean","median", "se", "sd",
2525
"cl_normal", "cl_boot"))
2626
type <- match.arg(type, c("two-way", "one-way"))
27+
# if (any(grepl("-", levels(data[,rlang::as_name(x), drop = TRUE])))){
28+
# stop("Factor names cannot contain dashes. Please recode factor levels before proceeding.")
29+
# }
2730
if (inherits(x, "quosure") & is.null(group)){
2831
letters.df <- place_tukey_letters(data, as_name(x), as_name(y), test = test,
2932
where = where, threshold = threshold)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ For more examples and details on different options for customization, please con
5454

5555
You can cite `ggtukey` as follows:
5656

57-
Bass, E. (2022). ggtukey: Compact Letter Displays for 'ggplot2' (v0.2.0). (https://ethanbass.github.io/ggtukey/).
57+
Bass, E. (2022). ggtukey: Compact Letter Displays for 'ggplot2' (v0.3.0). (https://ethanbass.github.io/ggtukey/).
5858

5959
# Further Reading
6060

inst/CITATION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ citEntry(
55
title = "ggtukey: Compact Letter Displays for 'ggplot2'",
66
author = "Ethan Bass",
77
year = "2023",
8-
note = "version 0.2.0",
8+
note = "version 0.3.0",
99
url = "https://ethanbass.github.io/ggtukey/",
1010
doi = "",
1111
textVersion = paste("Bass, E. (2023).",
12-
"ggtukey: Compact Letter Displays for 'ggplot2' (version 0.2.0)."
12+
"ggtukey: Compact Letter Displays for 'ggplot2' (version 0.3.0)."
1313
)
1414
)

man/geom_tukey.Rd

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)