R/geom_sigmark_interactive.R

Defines functions geom_sigmark_interactive

Documented in geom_sigmark_interactive

#' 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" or "group".
#' @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 colour A quoted character string of the variable from the `tbl_sig` df that applies the subgroup colours. Typically this is "sign".
#' @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 up
#'   \item full triangle down
#'   \item clear triangle up
#'   \item clear triangle down
#'   \item arrow up
#'   \item arrow down
#'   \item finger up
#'   \item finger down
#'   \item full star
#'   \item clear star
#'   \item checkmark
#'   \item asterisk
#'   \item heart
#'}
#' @export

geom_sigmark_interactive <- function(tbl_sig, x = "level", y = "pos", group = NULL, colour = "sign", icon = "full triangle up", tooltip = NULL, data_id = NULL, size = 5) {

	if (icon == "full triangle up") {
		icon <- sprintf("\u25b2")
	} else if (icon == "full triangle down") {
		icon <- sprintf("\u25bc")
	} else if (icon == "clear triangle up") {
		icon <- sprintf("\u25b3")
	} else if (icon == "clear triangle down") {
		icon <- sprintf("\u25bd")
	} else if (icon == "arrow up") {
		icon <- sprintf("\u2191")
	} else if (icon == "arrow down") {
		icon <- sprintf("\u2193")
	} else if (icon == "finger up") {
		icon <- sprintf("\u261d")
	} else if (icon == "finger down") {
		icon <- sprintf("\u261f")
	} else if (icon == "full star") {
		icon <- sprintf("\u2605")
	} else if (icon == "clear star") {
		icon <- sprintf("\u2606")
	} else if (icon == "checkmark") {
		icon <- sprintf("\u2714")
	} else if (icon == "asterisk") {
		icon <- sprintf("\u2731")
	} else if (icon == "heart") {
		icon <- sprintf("\u2764")
	}

	geom_sigmark_interactive <- base::list(
		ggiraph::geom_point_interactive(data = tbl_sig, shape = icon, size = size, ggplot2::aes_string(x = x, y = y, group = group, colour = colour, tooltip = tooltip, data_id = data_id)),
		ggplot2::scale_shape_manual(values = icon),
		ggplot2::guides(fill = ggplot2::guide_legend(override.aes = base::list(shape = NA), order = 1),
										shape = ggplot2::guide_legend(order = 9))
	)
	return(geom_sigmark_interactive)
}
philstraforelli/ggsigmark documentation built on May 20, 2019, 1:59 p.m.