Commit d405a2dd authored by houyun's avatar houyun
Browse files

set style

parent f628f345
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ S3method(print,calc_relimp)
S3method(print,correlate)
S3method(print,grouped_correlate)
S3method(print,grouped_matrix_data)
S3method(print,hyplot)
S3method(print,matrix_data)
S3method(print,random_forest)
S3method(qcorrplot,cor_md_tbl)
@@ -114,6 +115,8 @@ export(reorder_rows)
export(row_names)
export(secondary_x_axis)
export(secondary_y_axis)
export(set_corrplot_style)
export(set_default_style)
export(set_secondary_axis)
export(suffix_with)
export(theme_hy)

R/set-style.R

0 → 100644
+59 −0
Original line number Diff line number Diff line
#' @title Set Default Color Pallete
#' @description Set default color pallete for \code{\link{qcorrplot}}.
#' @param x a hyplot object.
#' @param colours vector of colours to use for n-colour gradient.
#' @param breaks a numeric vector of positions.
#' @param labels a character vector giving labels (must be same length as breaks).
#' @param limits a numeric vector of length two providing limits of the scale.
#' @param scale NULL or a \code{Scale} object.
#' @param ... other parameters passing to \code{\link[ggplot2]{scale_fill_gradientn}}.
#' @rdname set_style
#' @author Hou Yun
#' @export
print.hyplot <- function(x, ...) {
  if (inherits(x$data, "cor_md_tbl") &&
      !is.null(getOption("linkET.corrplot.style")) &&
      inherits(getOption("linkET.corrplot.style"), "Scale")) {
    x <- x + getOption("linkET.corrplot.style")
  }
  NextMethod(x)
}

#' @rdname set_style
#' @export
set_corrplot_style <- function(colours = NULL,
                               breaks = seq(-1, 1, length.out = 5),
                               labels = breaks,
                               limits = c(-1, 1),
                               scale = NULL,
                               ...) {
  style <- scale %||% corrplot_style(colours = colours,
                                     breaks = breaks,
                                     labels = labels,
                                     limits = limits,
                                     ...)
  options(linkET.corrplot.style = style)
}

#' @rdname set_style
#' @export
set_default_style <- function() {
  options(linkET.corrplot.style = NULL)
}

#' @noRd
corrplot_style <- function(colours = NULL,
                           breaks = seq(-1, 1, length.out = 5),
                           labels = breaks,
                           limits = c(-1, 1),
                           ...) {
  ggplot2::scale_fill_gradientn(colours = colours %||% red_blue,
                                breaks = breaks,
                                labels = labels,
                                limits = limits,
                                ...)
}

#' @noRd
red_blue <- c("#67001F", "#B2182B", "#D6604D", "#F4A582", "#FDDBC7", "#F7F7F7",
              "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC", "#053061")

man/set_style.Rd

0 → 100644
+42 −0
Original line number Diff line number Diff line
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/set-style.R
\name{print.hyplot}
\alias{print.hyplot}
\alias{set_corrplot_style}
\alias{set_default_style}
\title{Set Default Color Pallete}
\usage{
\method{print}{hyplot}(x, ...)

set_corrplot_style(
  colours = NULL,
  breaks = seq(-1, 1, length.out = 5),
  labels = breaks,
  limits = c(-1, 1),
  scale = NULL,
  ...
)

set_default_style()
}
\arguments{
\item{x}{a hyplot object.}

\item{...}{other parameters passing to \code{\link[ggplot2]{scale_fill_gradientn}}.}

\item{colours}{vector of colours to use for n-colour gradient.}

\item{breaks}{a numeric vector of positions.}

\item{labels}{a character vector giving labels (must be same length as breaks).}

\item{limits}{a numeric vector of length two providing limits of the scale.}

\item{scale}{NULL or a \code{Scale} object.}
}
\description{
Set default color pallete for \code{\link{qcorrplot}}.
}
\author{
Hou Yun
}