diff --git a/DESCRIPTION b/DESCRIPTION index 3354e82..78c4122 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,6 +29,7 @@ Collate: 'bricks_from_data.R' 'bricks_to_3d.R' 'collect_bricks.R' + 'coord_brick.R' 'geom_brick.R' 'geom_brick_col.R' 'geom_brick_point.R' diff --git a/NAMESPACE b/NAMESPACE index 54476e3..4f1a01f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export("%>%") +export(CoordBrick) export(GeomBrick) export(GeomBrickCol) export(bricks_from_coords) @@ -9,6 +10,7 @@ export(bricks_from_table) export(collect_3d) export(collect_bricks) export(convert_to_match_color) +export(coord_brick) export(display_3d) export(display_bricks) export(display_colors) diff --git a/R/coord_brick.R b/R/coord_brick.R new file mode 100644 index 0000000..a8c3511 --- /dev/null +++ b/R/coord_brick.R @@ -0,0 +1,30 @@ +#' Cartesian coordinates with fixed "aspect ratio" +#' +#' A fixed scale coordinate system forces a specified ratio between the +#' physical representation of data units on the axes. The ratio represents the +#' number of units on the y-axis equivalent to one unit on the x-axis. +#' +#' @export +#' @param ratio aspect ratio, expressed as `y / x` +#' +#' # Resize the plot to see that the specified aspect ratio is maintained +coord_brick <- function(ratio = 1, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") { + ggproto(NULL, CoordBrick, + limits = list(x = xlim, y = ylim), + ratio = ratio, + expand = expand, + clip = clip + ) +} + + + +#' @rdname brickr-ggproto +#' @export +CoordBrick <- ggproto("CoordBrick", CoordCartesian, + is_free = function() FALSE, + + aspect = function(self, ranges) { + 1 * self$ratio + } +) \ No newline at end of file diff --git a/man/brickr-ggproto.Rd b/man/brickr-ggproto.Rd index bb80495..8e8e54b 100644 --- a/man/brickr-ggproto.Rd +++ b/man/brickr-ggproto.Rd @@ -1,8 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/geom_brick.R, R/geom_brick_col.R, -% R/geom_brick_point.R, R/resizing_text_grob.R +% Please edit documentation in R/coord_brick.R, R/geom_brick.R, +% R/geom_brick_col.R, R/geom_brick_point.R, R/resizing_text_grob.R \docType{data} -\name{GeomBrick} +\name{CoordBrick} +\alias{CoordBrick} \alias{GeomBrick} \alias{GeomBrickCol} \alias{GeomStud} @@ -11,8 +12,10 @@ \alias{preDrawDetails.resizingTextGrob} \alias{postDrawDetails.resizingTextGrob} \title{GeomBrick} -\format{An object of class \code{GeomStud} (inherits from \code{Geom}, \code{ggproto}, \code{gg}) of length 5.} +\format{An object of class \code{CoordBrick} (inherits from \code{CoordCartesian}, \code{Coord}, \code{ggproto}, \code{gg}) of length 3.} \usage{ +CoordBrick + GeomStud resizingTextGrob(...) diff --git a/man/coord_brick.Rd b/man/coord_brick.Rd new file mode 100644 index 0000000..db04719 --- /dev/null +++ b/man/coord_brick.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/coord_brick.R +\name{coord_brick} +\alias{coord_brick} +\title{Cartesian coordinates with fixed "aspect ratio"} +\usage{ +coord_brick(ratio = 1, xlim = NULL, ylim = NULL, expand = TRUE, + clip = "on") +} +\arguments{ +\item{ratio}{aspect ratio, expressed as \code{y / x}Resize the plot to see that the specified aspect ratio is maintained} +} +\description{ +A fixed scale coordinate system forces a specified ratio between the +physical representation of data units on the axes. The ratio represents the +number of units on the y-axis equivalent to one unit on the x-axis. +}