Commit 99347746 authored by houyun's avatar houyun
Browse files

add geom_pairs

parent 72167fe2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ S3method(ggplot_add,doughnut)
S3method(ggplot_add,geom_couple)
S3method(ggplot_add,geom_diag_label)
S3method(ggplot_add,geom_ggplot)
S3method(ggplot_add,geom_pairs)
S3method(ggplot_add,geom_panel_grid)
S3method(ggplot_add,magic_text)
S3method(ggplot_add,secondary_axis)
@@ -110,6 +111,7 @@ export(geom_halfcircle)
export(geom_magic_text)
export(geom_mark)
export(geom_node_doughnut)
export(geom_pairs)
export(geom_panel_grid)
export(geom_shaping)
export(geom_square)
+64 −0
Original line number Diff line number Diff line
#' Pairs Later
#' @description This function can be used to add plot on a scattermatrix plot.
#' @inheritParams geom_ggplot
#' @param ID character, used to add elements based on ID.
#' @param theme a ggplot theme object.
#' @rdname geom_pairs
#' @author Hou Yun
#' @export
geom_pairs <- function(mapping = NULL,
                       data = NULL,
                       stat = "identity",
                       position = "identity",
                       ...,
                       ID = NULL,
                       theme = NULL,
                       rasterize = FALSE,
                       res = 100,
                       na.rm = FALSE,
                       show.legend = "collect",
                       inherit.aes = TRUE) {
  structure(list(mapping = mapping,
                 data = data,
                 stat = stat,
                 position = position,
                 ID = ID,
                 theme = theme,
                 rasterize = rasterize,
                 res = res,
                 na.rm = na.rm,
                 show.legend = show.legend,
                 inherit.aes = inherit.aes), class = "geom_pairs")
}

#' @method ggplot_add geom_pairs
#' @export
ggplot_add.geom_pairs <- function(object, plot, object_name) {
  data <- object$data %||% plot$data
  if (is.function(data)) {
    data <- data(plot$data)
  }
  if (!is.null(object$ID)) {
    id <- grepl(object$ID, data$ID)
    data <- data[id, , drop = FALSE]
  }

  if (empty(data)) {
    return(plot)
  }

  theme <- ggplot2::theme_get() + (object$theme %||% plot$theme) + theme_no_axis()
  theme$plot.margin <- ggplot2::margin()

  gglist <- lapply(seq_len(nrow(data)), function(ii) {
    .build_plot(plot = data$.plot[[ii]],
                type = data$.type[ii],
                pos = data$.type[ii],
                ptype = ptype,
                theme = theme)
  })
  object <- object[setdiff(names(object), c("ID", "theme"))]
  object$data <- data
  object$gglist <- gglist
  object <- do.call(geom_ggplot, object)
  ggplot_add(plot, object, object_name)
}

#' @noRd
.pairs_tbl <- function(data,

man/geom_pairs.Rd

0 → 100644
+81 −0
Original line number Diff line number Diff line
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/experimental-fun.R
\name{geom_pairs}
\alias{geom_pairs}
\title{Pairs Later}
\usage{
geom_pairs(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  ID = NULL,
  theme = NULL,
  rasterize = FALSE,
  res = 100,
  na.rm = FALSE,
  show.legend = "collect",
  inherit.aes = TRUE
)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}} or
\code{\link[ggplot2:aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the
default), it is combined with the default mapping at the top level of the
plot. You must supply \code{mapping} if there is no plot mapping.}

\item{data}{The data to be displayed in this layer. There are three
options:

If \code{NULL}, the default, the data is inherited from the plot
data as specified in the call to \code{\link[ggplot2:ggplot]{ggplot()}}.

A \code{data.frame}, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
\code{\link[ggplot2:fortify]{fortify()}} for which variables will be created.

A \code{function} will be called with a single argument,
the plot data. The return value must be a \code{data.frame}, and
will be used as the layer data. A \code{function} can be created
from a \code{formula} (e.g. \code{~ head(.x, 10)}).}

\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}

\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}

\item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are
often aesthetics, used to set an aesthetic to a fixed value, like
\code{colour = "red"} or \code{size = 3}. They may also be parameters
to the paired geom/stat.}

\item{ID}{character, used to add elements based on ID.}

\item{theme}{a ggplot theme object.}

\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.}

\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.
It can also be a named logical vector to finely select the aesthetics to
display.}

\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.}
}
\description{
This function can be used to add plot on a scattermatrix plot.
}
\author{
Hou Yun
}