Commit fab4cab0 authored by houyun's avatar houyun
Browse files

can set own resolution

parent ca355fdd
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ draw_key_marker <- function(data, params, size) {
#' @inheritParams ggplot2::geom_polygon
#' @param width_unit,height_unit units of width or height.
#' @param rasterize logical, whether to convert raster image before drawing.
#' @param res positive numeric, used to set the resolution of raster.
#' @section Aesthetics:
#' \code{geom_shaping()} understands the following aesthetics (required aesthetics are in bold):
#'     \itemize{
@@ -70,12 +71,14 @@ geom_shaping <- function(mapping = NULL,
                         width_unit = "native",
                         height_unit = width_unit,
                         rasterize = FALSE,
                         res = 100,
                         na.rm = FALSE,
                         show.legend = NA,
                         inherit.aes = TRUE) {
  params <- rename(list(width_unit = width_unit,
                        height_unit = height_unit,
                        rasterize = rasterize,
                        res = res,
                        na.rm = na.rm,
                        ...), "shaping" = "marker")
  if ("shaping" %in% names(params)) {
@@ -106,7 +109,8 @@ Geomshaping <- ggproto(
  required_aes = c("x", "y"),

  draw_panel = function(self, data, panel_params, coord, shaping = NULL,
                        width_unit = NULL, height_unit = NULL, rasterize = FALSE) {
                        width_unit = NULL, height_unit = NULL, rasterize = FALSE,
                        res = 100) {
    if (empty(data)) {
      return(nullGrob())
    }
@@ -157,6 +161,7 @@ Geomshaping <- ggproto(
               hjust = data$hjust,
               vjust = data$vjust,
               rasterize = rasterize,
               res = res,
               default.units = "native",
               gp = gpar(col  = scales::alpha(data$colour, data$alpha),
                         fill = scales::alpha(data$fill, data$alpha),
+6 −3
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ markerGrob <- function(marker,
                       hjust = 0.5,
                       vjust = 0.5,
                       rasterize = FALSE,
                       res = 100,
                       default.units = "npc",
                       gp = gpar(),
                       name = NULL,
@@ -195,6 +196,7 @@ markerGrob <- function(marker,
              hjust = hjust,
              vjust = vjust,
              rasterize = rasterize,
              res = res,
              default.units = default.units,
              gp = gp,
              name = name,
@@ -224,9 +226,10 @@ makeContent.markerGrob <- function(x) {

  if (isTRUE(x$rasterize)) {
    agg_capture <- get_function("ragg", "agg_capture")
    dim_inch <- dev.size("in")
    dim_pt <- dev.size("px")
    res <- dim_pt[1] / dim_inch[1]
    res <- dev.size("px")[1] / dev.size("in")[1]
    if (x$res > res) {
      res <- x$res
    }

    grobs <- pmap(list(grobs, gp, x$x, x$y, width, height, x$angle, x$hjust, x$vjust),
                  function(.grob, .gp, .x, .y, .width, .height, .angle, .hjust, .vjust) {
+3 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ geom_shaping(
  width_unit = "native",
  height_unit = width_unit,
  rasterize = FALSE,
  res = 100,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
@@ -56,6 +57,8 @@ to the paired geom/stat.}

\item{rasterize}{logical, whether to convert raster image before drawing.}

\item{res}{positive numeric, used to set the resolution of raster.}

\item{na.rm}{If \code{FALSE}, the default, missing values are removed with
a warning. If \code{TRUE}, missing values are silently removed.}