Git Product home page Git Product logo

Comments (2)

shamindras avatar shamindras commented on July 30, 2024

For roxygen2 documentation, we can adopt the following convention,
mainly from Hadley Wickham's R packages section,
but with some changes. Some guidelines specific to our package are:

  1. The first line is the high level title. It should not end in a period . see here
  2. There should be a 1 line gap between all main fields e.g. between @param and @return. This is a little unconventional, but I feel good practice, see here.
  3. The first line of the description should begin with code{function_name}, see here.
  4. For the @examples section we should always use set.seed for reproducibility, see here.
  5. Any block that begins with a keyword e.g. @details, @param, @return etc, and is split over multiple lines, should have the second and onward lines indented by 2 spaces, see here.
  6. We should use indented code blocks in our @examples section, see here
  7. Each specification of @param should start as "A numeric/character/etc scalar/vector/etc; ..." or "A numeric/character/etc scalar/vector/etc indicating ...."

from maars.

shamindras avatar shamindras commented on July 30, 2024

For the ggplot2 wrapper, we can do something simple like this and put in our utils-common.R:

#' Set the custom \code{\link[ggplot2]{theme}} for our plots
#' 
#' \code{set_ggplot2_theme} is a wrapper to set a standard custom 
#' \code{\link[ggplot2]{theme}} for all of our output plots. It contains 
#' only the necessary parameters we require to change in the
#' \code{\link[ggplot2]{theme}} function, and takes the remaining arguments
#' as the default values.
#'
#' @param ggplot_obj A \code{\link[ggplot2]{ggplot2}} object
#' @param axis_text_size A positive integer to define the the size of the x and 
#'   y axis text in our \code{\link[ggplot2]{ggplot2}} object
#' @param axis_title_size A positive integer to define the the size of the x and 
#'   y axis text in our \code{\link[ggplot2]{ggplot2}} object 
#' @param strip_text_x_size A positive integer to define the the size of the x and 
#'   y axis text in our \code{\link[ggplot2]{ggplot2}} object 
#' @param legend_text_size A positive integer to define the the size of the x and 
#'   y axis text in our \code{\link[ggplot2]{ggplot2}} object 
#' @param legend_title_size A positive integer to define the the size of the x and 
#'   y axis text in our \code{\link[ggplot2]{ggplot2}} object 
#' @param legend_position A character value the position of legends 
#' ("none", "left", "right", "bottom", "top", or two-element numeric vector)
#'
#' @return
#' @export
#'
#' @examples
set_ggplot2_theme <- function(ggplot_obj,
                              axis_text_size = 17,
                              axis_title_size = 17,
                              strip_text_x_size = 17,
                              legend_text_size = 17,
                              legend_title_size = 17,
                              legend_position = "bottom") {
  out <- ggplot_obj +
    ggplot2::theme_bw() +
    ggplot2::theme(
      axis.text = ggplot2::element_text(size = axis_text_size),
      axis.title = ggplot2::element_text(size = axis_title_size),
      strip.text.x = ggplot2::element_text(size = strip_text_x_size),
      legend.text = ggplot2::element_text(size = legend_text_size),
      legend.title = ggplot2::element_text(size = legend_title_size),
      legend.position = legend_position
    )
  
  return(out)
}

We could then call on this function as follows:

library(ggplot2)
p1 <- ggplot2::ggplot(mtcars, aes(x = wt, y = mpg, size = disp)) +
      ggplot2::geom_point()

# Set the theme for a `ggplot2` object with the default options
out <- p1 %>% maars::set_ggplot2_theme(ggplot_obj = .)

NOTE: This is now created in utils-common.R. There is also a test-utils-common.R file.

from maars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.