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 where Where to put the letters. Either above the box (\code{box}),
9- # ' above the upper whisker (\code{whisker}), or at the \code{mean} or
10- # ' \code{median}.
11- # ' @param hjust Horizontal adjustment of the label. Argument to \code{\link[ggplot2]{geom_text}}.
12- # ' @param vjust Vertical adjustment of the label. Argument to \code{\link[ggplot2]{geom_text}}.
8+ # ' @param where Where to put the letters. Either above the box (\code{box}) or
9+ # ' upper whisker (\code{whisker}) of a boxplot; at the \code{mean} or
10+ # ' \code{median}; or at the top of the error bars calculated from the standard
11+ # ' error (\code{se}), standard deviation \code{sd}, or 95% confidence intervals
12+ # ' returned by \code{\link[Hmisc]{smean.cl.normal}}, or \code{\link[Hmisc]{smean.cl.boot}}.
13+ # ' @param hjust Horizontal adjustment of the label. (Argument to \code{\link[ggplot2]{geom_text}}).
14+ # ' @param vjust Vertical adjustment of the label. (Argument to \code{\link[ggplot2]{geom_text}}).
1315# ' @param size Label size. Argument to \code{\link[ggplot2]{geom_text}}.
1416# ' @param na.rm Logical. Whether to remove observations with NAs for the provided
1517# ' factors (i.e. \code{x} and \code{group}) before plotting. Defaults to TRUE.
2628# ' * Graves S, Piepho H, Dorai-Raj LSwhfS (2019). multcompView: Visualizations
2729# ' of Paired Comparisons. R package version 0.1-8. \url{https://CRAN.R-project.org/package=multcompView}
2830# '
29- # ' @note Thank you to Hiroaki Yutani (\url{https://yutani.rbind.io/post/2017-11-07-ggplot-add/})
30- # ' and Simon P Couch (\url{https://www.simonpcouch.com/blog/ggplot-pipe-plus/})
31- # ' for a couple of very helpful blog posts describing the \code{\link[ggplot2]{ggplot_add}}
32- # ' syntax.
31+ # ' @note Thank you to \href{https://github.com/yutannihilation}{Hiroaki Yutani}
32+ # ' and \href{https://github.com/simonpcouch}{Simon P. Couch} for a couple of
33+ # ' very helpful blog posts (\href{https://yutani.rbind.io/post/2017-11-07-ggplot-add/}{1},
34+ # ' \href{https://www.simonpcouch.com/blog/ggplot-pipe-plus/}{2}) describing the
35+ # ' \code{\link[ggplot2]{ggplot_add}} syntax.
3336# ' @examples
3437# ' library(ggplot2)
3538# ' set.seed(1)
4245
4346geom_tukey <- function (test = c(" tukey" ," kruskalmc" ), threshold = 0.05 ,
4447 type = c(" two-way" , " one-way" ),
45- where = c(" box" ," whisker" , " mean" , " median" ),
46- hjust = 0 , vjust = 0 , size = 4 , na.rm = TRUE ){
48+ where = c(" box" ," whisker" , " mean" , " median" , " se" , " sd" ,
49+ " cl_normal" , " cl_boot" ),
50+ hjust = 0 , vjust = - 0.2 , size = 4 , na.rm = TRUE ){
4751 # store inputs in classed output that can
4852 # be passed to a `ggplot_add` method
4953 test <- match.arg(test , c(" tukey" , " kruskalmc" ))
54+ if (is.numeric(type )){
55+ type <- switch (type , " 1" = " one-way" , " 2" = " two-way" )
56+ }
5057 type <- match.arg(type , c(" two-way" , " one-way" ))
51- where <- match.arg(where , c(" box" ," whisker" , " mean" , " median" ))
58+ where <- match.arg(where , c(" box" , " whisker" , " mean" , " median" ,
59+ " se" , " sd" ," cl_normal" ," cl_boot" ))
5260 if (test == " kruskalmc" ){
5361 type <- " one-way"
5462 }
@@ -71,8 +79,8 @@ geom_tukey <- function(test = c("tukey","kruskalmc"), threshold = 0.05,
7179# ' @noRd
7280geom_tukey_ <- function (p , test = c(" tukey" ," kruskalmc" ), threshold = 0.05 ,
7381 type = c(" two-way" , " one-way" ),
74- where = c(" box" ," whisker" , " mean" ," median" ),
75- hjust = 0 , vjust = 0 , size = 4 , na.rm = TRUE ) {
82+ where = c(" box" ," whisker" , " mean" ," median" , " se " , " sd " , " cl_normal " , " cl_boot " ),
83+ hjust = 0 , vjust = 0 , size = 4 , na.rm = TRUE ) {
7684 data <- p $ data
7785 if (na.rm ){
7886 data <- drop_na(data , !! p $ mapping $ x , !! p $ facet $ params $ facets [[1 ]])
@@ -85,7 +93,7 @@ geom_tukey_ <- function(p, test = c("tukey","kruskalmc"), threshold = 0.05,
8593 data <- get_tukey_letters(data = data ,
8694 x = c(p $ mapping $ x , p $ facet $ params $ facets [[1 ]]),
8795 y = p $ mapping $ y , test = test ,
88- where = where ,type = type ,
96+ where = where , type = type ,
8997 threshold = threshold )
9098 } else if (type == " one-way" ){
9199 data <- get_tukey_letters(data = data ,
0 commit comments