Commit 4dc72126 authored by houyun's avatar houyun
Browse files

auto parse label

parent 5bbcbfb3
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -186,6 +186,7 @@ annotateGrob.grob <- function(annotate,
              cl = "annotateGrob")
}

#' @param parse if TRUE (default) will convert text to richtext.
#' @rdname geom_annotate
#' @method annotateGrob character
#' @export
@@ -196,14 +197,24 @@ annotateGrob.character <- function(annotate,
                                   nudge_x = 0,
                                   nudge_y = 0,
                                   default.units = "npc",
                                   parse = FALSE,
                                   ...) {
  params <- list(...)
  if (isTRUE(parse)) {
    annotate <- latex_richtext(annotate,
                               sup = params$sup %||% "^",
                               sub = params$sub %||% "_",
                               br = params$br %||% "\n")
  }
  params <- params[setdiff(names(params), c("sup", "sub", "br"))]

  if (is_richtext(annotate)) {
    textbox_grob <- get_function("gridtext", "textbox_grob")
    annotate <- paste_with_na(annotate, collapse = "<br>")
    annotate <- textbox_grob(annotate, ...)
    params$text <- paste_with_na(annotate, collapse = "<br>")
    annotate <- do.call(textbox_grob, params)
  } else {
    annotate <- paste_with_na(annotate, collapse = "\n")
    annotate <- grid::textGrob(annotate, ...)
    params$label <- paste_with_na(annotate, collapse = "\n")
    annotate <- do.call(grid::textGrob, params)
  }

  annotateGrob(annotate = annotate,
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ annotateGrob(annotate, ...)
  nudge_x = 0,
  nudge_y = 0,
  default.units = "npc",
  parse = FALSE,
  ...
)

@@ -147,6 +148,8 @@ display.}

\item{default.units}{A string indicating the default units to use.}

\item{parse}{if TRUE (default) will convert text to richtext.}

\item{digits}{integer indicating the number of decimal places (round)
to be used, the default value is 2.}