#' Significance Markers for ggplot2
#' @description Apply significance markers onto an existing \link[ggplot2]{ggplot2} chart
#' @param tbl_sig A df object created from \link[ggsigmark]{tbl_sig} functions.
#' @param x A quoted character string of the variable from the `tbl_sig` df charted on the x-axis. Typically this is "level".
#' @param y A quoted character string of the variable from the `tbl_sig` df charted on the y-axis. Typically this is "pos".
#' @param group An optional quoted character string of the variable from the `tbl_sig` df that is grouped. If needed, it likely needs to be "group".
#' @param direction A quoted character string of the variable from the `tbl_sig` df indicating whether the change from one wave to the next is up or down. Typically this is "direction".
#' @param colour A quoted character string of the variable from the `tbl_sig` df that applies the subgroup colours. Typically this is "level".
#' @param fill A quoted character string of the variable from the `tbl_sig` df that applies the subgroup colours. Typically this is "level".
#' @param labels A quoted character string vector indicating how the sig. test markers should be labeled in the legend. By default, the labels are "Increase" and "Decrease".
#' @param icon A quoted character string indicating the type of icon to display to denote statistical significance.
#' @param tooltip A quoted character string of the variable from the `tbl_sig` df that will be displayed when the mouse hovers a sigmark object. See \link[ggiraph]{ggiraph} for more details.
#' @param data_id A quoted character string of the variable from the `tbl_sig` df that will be highlighted when the user clicks on a sigmark object. See \link[ggiraph]{ggiraph} for more details.
#' @param size A numeric value indicating the size of the icon. Default is set to 5.
#'
#' @details This is essentially a wrapper for \link[ggiraph]{geom_point_interactive}
#'
#' @note The icon argument accepts one of the following strings:
#' \itemize{
#' \item full triangle
#' \item clear triangle
#' \item arrow
#' \item finger
#'}
#' @export
geom_sigmark_waves_interactive <- function(tbl_sig, x = "wave_pos", y = "result_pos", group = NULL,
direction = "Direction", labels = c("Increase", "Decrease"), colour = "level",
fill = "level", tooltip = NULL, data_id = NULL, icon = "full triangle", size = 5) {
if (icon == "full triangle") {
icon_up <- 24 #base::sprintf("\u25b2")
icon_down <- 25 #base::sprintf("\u25bc")
} else if (icon == "clear triangle") {
icon_up <- 2 #base::sprintf("\u25b3")
icon_down <- 6 #base::sprintf("\u25bd")
} else if (icon == "arrow") {
icon_up <- base::sprintf("\u2191")
icon_down <- base::sprintf("\u2193")
} else if (icon == "finger") {
icon_up <- base::sprintf("\u261d")
icon_down <- base::sprintf("\u261f")
}
base::levels(tbl_sig[[direction]]) <- labels
icons <- base::c(icon_up, icon_down)
base::names(icons) <- labels
geom_sigmark_waves_interactive <- base::list(
ggiraph::geom_point_interactive(data = tbl_sig, ggplot2::aes_string(x = x, y = y, group = group, colour = colour, fill = fill, tooltip = tooltip, data_id = data_id, shape = direction), size = size),
ggplot2::scale_shape_manual(values = icons),
ggplot2::guides(colour = ggplot2::guide_legend(override.aes = base::list(shape = NA), order = 1),
shape = ggplot2::guide_legend(order = 9),
fill = FALSE)
)
return(geom_sigmark_waves_interactive)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.