-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: label_tex as an extention of ggplot2::label_parsed (#160)
- Loading branch information
Showing
5 changed files
with
75 additions
and
0 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
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,33 @@ | ||
#' A labeller function to parse TeX syntax | ||
#' | ||
#' This function formats the strip labels of facet grids and wraps that contains | ||
#' TeX expressions. The latex2exp package must be installed. | ||
#' | ||
#' @seealso [ggplot2::labeller], [latex2exp::TeX()] | ||
#' | ||
#' @inheritParams ggplot2::label_parsed | ||
#' @inheritDotParams ggplot2::label_parsed -labels | ||
#' | ||
#' @examples | ||
#' # requires latex2exp package be installed | ||
#' if (requireNamespace("latex2exp", quietly = TRUE)) { | ||
#' library(ggplot2) | ||
#' d <- data.frame(x = 1, y = 1, facet = "$\\beta$") | ||
#' ggplot(d, aes(x, y)) + | ||
#' geom_point() + | ||
#' facet_wrap(~ facet, labeller = label_tex) | ||
#' } | ||
#' @importFrom ggplot2 label_parsed | ||
#' @export | ||
label_tex <- function(labels, ...) { | ||
if (!requireNamespace("latex2exp", quiet = TRUE)) { | ||
stop("The latex2exp package is needed for this functionality", call. = FALSE) | ||
} | ||
label_parsed( | ||
as.data.frame( | ||
lapply(labels, latex2exp::TeX, output = "character"), | ||
stringsAsFactors = FALSE | ||
), | ||
... | ||
) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.