mirror of
https://github.com/ryantimpe/brickr.git
synced 2026-01-07 06:10:56 -06:00
Big updates to documentation. Longggg way to go.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -63,3 +63,4 @@ ryanweb.mp4
|
||||
forestmovie.mp4
|
||||
forestweb.mp4
|
||||
test_*
|
||||
brickr.Rproj
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Package: brickr
|
||||
Title: Create Simulated LEGO Models from Images or Data Frames
|
||||
Version: 0.1.0.9002
|
||||
Version: 0.1.0.9003
|
||||
Authors@R:
|
||||
person(given = "Ryan",
|
||||
family = "Timpe",
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
#' Cartesian coordinates with fixed "aspect ratio"
|
||||
#' Cartesian coordinates for bricks
|
||||
#'
|
||||
#' 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.
|
||||
#' A fixed scale coordinate system that ensures correct brick proportions are maintained regardless of device size.
|
||||
#' Use \code{coord_brick_flip()} for horizontal bars.
|
||||
#'
|
||||
#' @inheritParams ggplot2::coord_fixed
|
||||
#' @examples
|
||||
#' #geom_brick_col should be used in conjunction with other brickr charting functions, especially coord_brick.
|
||||
#' df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
|
||||
#' ggplot(df, aes(trt, outcome)) +
|
||||
#' geom_brick_col(aes(fill = trt)) +
|
||||
#' coord_brick()
|
||||
#'
|
||||
#' #horizontal bars
|
||||
#' @export
|
||||
#' @rdname coord_brick
|
||||
coord_brick <- function(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") {
|
||||
ggproto(NULL, CoordBrick,
|
||||
limits = list(x = xlim, y = ylim),
|
||||
@@ -13,13 +22,8 @@ coord_brick <- function(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") {
|
||||
)
|
||||
}
|
||||
|
||||
#' Flipped 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. X- and y- axes are flipped.
|
||||
#'
|
||||
#' @export
|
||||
#' @rdname coord_brick
|
||||
coord_brick_flip <- function(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") {
|
||||
ggproto(NULL, CoordBrickFlip,
|
||||
limits = list(x = xlim, y = ylim),
|
||||
|
||||
@@ -1,8 +1,36 @@
|
||||
#' Bar charts with bricks
|
||||
#'
|
||||
#' `geom_brick_col()` is the \code{brickr} version of `ggplot2::geom_col()`.
|
||||
#' Bar height is determined by values in the data using the \code{y} aesthetic. With the exception of \code{fill}, aesthetics available in `ggplot2::geom_col()` are generally not enabled here.
|
||||
#
|
||||
#' @inheritParams ggplot2::geom_col
|
||||
#' @param label Character string to include as embossed text inside brick knobs. Maximum 6 characters.
|
||||
#' @param label_scale Scale text size of label as a percentage.
|
||||
#' Sizing for the embossed text can be off. A best attempt at the text size is calculated from the device size. Zooming a plot in the RStudio window will not update the text size.
|
||||
#' If the automated size doesn't look correct after rendering the chart, use this scale.
|
||||
#' @param two_knob Logical. Each bar is two knobs / studs wide. When rendering many \code{x} values, set to \code{FALSE}.
|
||||
#' @param split_bricks Logical. For simpler bars, do not split into individual bricks. Knobs still render.
|
||||
#' @param min_radius_for_text Knob radius as a percentage of view port. If the calculated radius is lower than this value, embossed label will not appear in knobs.
|
||||
#' @param position It it not recommended to use \code{position = "stack"}.
|
||||
#' @examples
|
||||
#' #geom_brick_col should be used in conjunction with other brickr charting functions, especially coord_brick.
|
||||
#' df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
|
||||
#' ggplot(df, aes(trt, outcome)) +
|
||||
#' geom_brick_col() +
|
||||
#' coord_brick()
|
||||
#'
|
||||
#' #For official LEGO colors, use with scale_fill_brick and theme_brick.
|
||||
#' ggplot(df, aes(trt, outcome)) +
|
||||
#' geom_brick_col(aes(fill = trt)) +
|
||||
#' scale_fill_brick() +
|
||||
#' coord_brick() +
|
||||
#' theme_brick()
|
||||
#'
|
||||
#' @export
|
||||
#' @rdname geom_brick_rect
|
||||
|
||||
geom_brick_col <- function(mapping = NULL, data = NULL,
|
||||
position = "dodge", two_knob = TRUE, split_bricks = TRUE,
|
||||
min_radius_for_text = 0.02,
|
||||
min_radius_for_text = 0.02, label = "brickr", label_scale = 1,
|
||||
...,
|
||||
width = NULL,
|
||||
na.rm = FALSE,
|
||||
@@ -22,6 +50,7 @@ geom_brick_col <- function(mapping = NULL, data = NULL,
|
||||
two_knob = two_knob,
|
||||
split_bricks = split_bricks,
|
||||
min_radius_for_text = min_radius_for_text,
|
||||
label_scale = label_scale,
|
||||
na.rm = na.rm,
|
||||
...
|
||||
)
|
||||
@@ -35,7 +64,7 @@ geom_brick_col <- function(mapping = NULL, data = NULL,
|
||||
#' @include geom_brick.R
|
||||
GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
default_aes = aes(colour = "#333333", fill = "#C4281B", size = 0.25, linetype = 1,
|
||||
alpha = NA, label = "LEGO",
|
||||
alpha = NA, label = "brickr",
|
||||
angle = 0, family = "", fontface = 1, lineheight = 1.2),
|
||||
required_aes = c("x", "y"),
|
||||
|
||||
@@ -58,7 +87,7 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
|
||||
draw_panel = function(self, data, panel_params, coord, linejoin = "mitre",
|
||||
min_radius_for_text = 0.02, width=NULL,
|
||||
two_knob = TRUE, split_bricks = TRUE) {
|
||||
two_knob = TRUE, split_bricks = TRUE, label_scale =1) {
|
||||
|
||||
#This happens to EACH panel
|
||||
|
||||
@@ -77,7 +106,7 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
coords_rect <- flip_coords(coords_rect)
|
||||
}
|
||||
|
||||
test_coords_rect <<- coords_rect
|
||||
# test_coords_rect <<- coords_rect
|
||||
|
||||
# Split the bricks into 4-knob long bricks. This can be turned on and off
|
||||
if(split_bricks){
|
||||
@@ -105,7 +134,7 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
dplyr::ungroup()
|
||||
})
|
||||
|
||||
test_coords_rect2 <<- coords_rect_complete_bricks
|
||||
# test_coords_rect2 <<- coords_rect_complete_bricks
|
||||
|
||||
coords_rect_unflipped <- dplyr::bind_rows(
|
||||
#Knobbed-bricks
|
||||
@@ -114,8 +143,8 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
#Unknobbed caps
|
||||
coords_rect_complete_bricks %>%
|
||||
dplyr::group_by(PANEL, group) %>%
|
||||
dplyr::filter((n() > 1 && num_of_knobs_in_this_brick > 0) |
|
||||
n() == 1) %>%
|
||||
dplyr::filter((dplyr::n() > 1 && num_of_knobs_in_this_brick > 0) |
|
||||
dplyr::n() == 1) %>%
|
||||
dplyr::filter(ymax == max(ymax)) %>%
|
||||
dplyr::ungroup() %>%
|
||||
dplyr::mutate(ymin = ymax,
|
||||
@@ -135,8 +164,8 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
|
||||
} #End split_bricks
|
||||
|
||||
test_coords_rect3 <<- coords_rect_unflipped
|
||||
test_coords_rect4 <<- coords_rect
|
||||
# test_coords_rect3 <<- coords_rect_unflipped
|
||||
# test_coords_rect4 <<- coords_rect
|
||||
|
||||
#Brighter colors for darker bricks
|
||||
coords_rect$color_intensity <- as.numeric(colSums(col2rgb(coords_rect$fill)))
|
||||
@@ -166,7 +195,7 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
# Knobs ----
|
||||
|
||||
coords <- coord$transform(data, panel_params)
|
||||
coords_knobs0 <<- coords
|
||||
# coords_knobs0 <<- coords
|
||||
|
||||
#Reverse calc for flipped
|
||||
if(coord$is_linear() == "flipped"){
|
||||
@@ -178,7 +207,7 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
num_of_1x1s = (ymax-ymin) %/% brick_width,
|
||||
knob_radius = brick_width * (5/8) * (1/2) )
|
||||
|
||||
coords_knobs0a <<- knobs_dims
|
||||
# coords_knobs0a <<- knobs_dims
|
||||
|
||||
coords_knobs <- 1:max(knobs_dims$num_of_1x1s) %>%
|
||||
purrr::map_dfr(function(kk){
|
||||
@@ -199,7 +228,7 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
|
||||
})
|
||||
|
||||
coords_knobs1 <<- coords_knobs
|
||||
# coords_knobs1 <<- coords_knobs
|
||||
|
||||
#Outline and text for dark colors
|
||||
coords_knobs$color_intensity <- as.numeric(colSums(col2rgb(coords_knobs$fill)))
|
||||
@@ -263,7 +292,7 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
gp = grid::gpar(
|
||||
col = alpha(coords_knobs$text_col, coords_knobs$text_alpha),
|
||||
fontsize = fs,
|
||||
cex = (3/8) * 0.5 * ((coords_knobs$knob_radius / 0.03)^(1/2)),
|
||||
cex = (3/8) * 0.75 * ((coords_knobs$knob_radius / 0.03)^(1/2)) * label_scale,
|
||||
# fontfamily = data$family,
|
||||
fontface = "bold"#,
|
||||
# lineheight = data$lineheight
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
#' Create your own discrete scale
|
||||
#' Color scales for bricks
|
||||
#'
|
||||
#' These functions allow you to specify your own set of mappings from levels in the
|
||||
#' data to aesthetic values.
|
||||
#' brickr counterpart to \code{ggplot2::scale_fill_discrete()} to map bar colors to the palette of LEGO mold colors.
|
||||
#'
|
||||
#' The functions `scale_colour_manual()`, `scale_fill_manual()`, `scale_size_manual()`,
|
||||
#' etc. work on the aesthetics specified in the scale name: `colour`, `fill`, `size`,
|
||||
#' etc. However, the functions `scale_colour_manual()` and `scale_fill_manual()` also
|
||||
#' have an optional `aesthetics` argument that can be used to define both `colour` and
|
||||
#' `fill` aesthetic mappings via a single function call (see examples). The function
|
||||
#' `scale_discrete_manual()` is a generic scale that can work with any aesthetic or set
|
||||
#' of aesthetics provided via the `aesthetics` argument.
|
||||
#'
|
||||
#' @param brick_theme Color options for brickr.
|
||||
#' @param ... Other parameters from ggplots::scale_fill_manual().
|
||||
#' @section Color Blindness:
|
||||
#' Many color palettes derived from RGB combinations (like the "rainbow" color
|
||||
#' palette) are not suitable to support all viewers, especially those with
|
||||
#' color vision deficiencies. Using `viridis` type, which is perceptually
|
||||
#' uniform in both colour and black-and-white display is an easy option to
|
||||
#' ensure good perceptive properties of your visulizations.
|
||||
#' The colorspace package offers functionalities
|
||||
#' - to generate color palettes with good perceptive properties,
|
||||
#' - to analyse a given color palette, like emulating color blindness,
|
||||
#' - and to modify a given color palette for better perceptivity.
|
||||
#'
|
||||
#' For more information on color vision deficiencies and suitable color choices
|
||||
#' see the [paper on the colorspace package](https://arxiv.org/abs/1903.06490)
|
||||
#' and references therein.
|
||||
#' @inheritParams ggplot2::scale_fill_manual
|
||||
#' @param brick_theme Color palette for bricks. Same as \code{brickr::theme_brick()}. Options include:
|
||||
#' \code{ c("classic", "hp", "sw_light", "sw_dark", "friends", "elves",
|
||||
#' "ninja", "classy", "city", "ocean", "movie", "space",
|
||||
#' "jurassic", "duplo", "superhero",
|
||||
#' "rainbow7", "rainbow13", "doublerainbow", "blue")}.
|
||||
#' @examples
|
||||
#' p <- ggplot(mtcars, aes(mpg, wt)) +
|
||||
#' geom_point(aes(colour = factor(cyl)))
|
||||
#' p + scale_colour_manual(values = c("red", "blue", "green"))
|
||||
#' df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
|
||||
#' p <- ggplot(df, aes(trt, outcome)) +
|
||||
#' geom_brick_col(aes(fill = trt)) +
|
||||
#' coord_brick()
|
||||
#'
|
||||
#' p + scale_fill_brick()
|
||||
#'
|
||||
#' #Select a brick_theme and use with theme_brick()
|
||||
#' tm <- "hp"
|
||||
#' p +
|
||||
#' scale_fill_brick(tm) +
|
||||
#' theme_brick(tm)
|
||||
#' @export
|
||||
|
||||
scale_fill_brick <- function(brick_theme = "classic", ...) {
|
||||
@@ -38,6 +28,7 @@ scale_fill_brick <- function(brick_theme = "classic", ...) {
|
||||
if(!(brick_theme %in% brickr_themes$theme)){
|
||||
warning(paste0("Defaulting scale_brick() to 'classic'. Use a brick_theme included in brickr:\n",
|
||||
paste(unique(brickr_themes$theme), collapse = ", ")))
|
||||
brick_theme <- "classic"
|
||||
}
|
||||
|
||||
values <- brickr_themes[brickr_themes$theme == brick_theme &
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
#' Modify components of a theme
|
||||
#'
|
||||
#' Themes are a powerful way to customize the non-data components of your
|
||||
#' plots: i.e. titles, labels, fonts, background, gridlines, and legends.
|
||||
#' Themes can be used to give plots a consistent customized look.
|
||||
#' Modify a single plot's theme using `theme()`; see [theme_update()] if
|
||||
#' you want modify the active theme, to affect all subsequent plots. Theme
|
||||
#' elements are documented together according to inheritance, read more
|
||||
#' about theme inheritance below.
|
||||
#'
|
||||
#' Brick color themes
|
||||
|
||||
#'@export
|
||||
|
||||
theme_brick <- function(brick_theme = "classic"){
|
||||
if(!(brick_theme %in% brickr_themes$theme)){
|
||||
warning(paste0("Defaulting theme_brick() to 'classic'. Use a brick_theme included in brickr:\n",
|
||||
paste(unique(brickr_themes$theme), collapse = ", ")))
|
||||
brick_theme <- "classic"
|
||||
}
|
||||
|
||||
values <- brickr_themes[brickr_themes$theme == brick_theme &
|
||||
|
||||
@@ -9,3 +9,8 @@
|
||||
#' @importFrom magrittr %>%
|
||||
#' @usage lhs \%>\% rhs
|
||||
NULL
|
||||
|
||||
|
||||
"%||%" <- function(a, b) {
|
||||
if (!is.null(a)) a else b
|
||||
}
|
||||
@@ -2,12 +2,42 @@
|
||||
% Please edit documentation in R/coord_brick.R
|
||||
\name{coord_brick}
|
||||
\alias{coord_brick}
|
||||
\title{Cartesian coordinates with fixed "aspect ratio"}
|
||||
\alias{coord_brick_flip}
|
||||
\title{Cartesian coordinates for bricks}
|
||||
\usage{
|
||||
coord_brick(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on")
|
||||
|
||||
coord_brick_flip(xlim = NULL, ylim = NULL, expand = TRUE,
|
||||
clip = "on")
|
||||
}
|
||||
\arguments{
|
||||
\item{xlim}{Limits for the x and y axes.}
|
||||
|
||||
\item{ylim}{Limits for the x and y axes.}
|
||||
|
||||
\item{expand}{If \code{TRUE}, the default, adds a small expansion factor to
|
||||
the limits to ensure that data and axes don't overlap. If \code{FALSE},
|
||||
limits are taken exactly from the data or \code{xlim}/\code{ylim}.}
|
||||
|
||||
\item{clip}{Should drawing be clipped to the extent of the plot panel? A
|
||||
setting of \code{"on"} (the default) means yes, and a setting of \code{"off"}
|
||||
means no. In most cases, the default of \code{"on"} should not be changed,
|
||||
as setting \code{clip = "off"} can cause unexpected results. It allows
|
||||
drawing of data points anywhere on the plot, including in the plot margins. If
|
||||
limits are set via \code{xlim} and \code{ylim} and some data points fall outside those
|
||||
limits, then those data points may show up in places such as the axes, the
|
||||
legend, the plot title, or the plot margins.}
|
||||
}
|
||||
\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.
|
||||
A fixed scale coordinate system that ensures correct brick proportions are maintained regardless of device size.
|
||||
Use \code{coord_brick_flip()} for horizontal bars.
|
||||
}
|
||||
\examples{
|
||||
#geom_brick_col should be used in conjunction with other brickr charting functions, especially coord_brick.
|
||||
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
|
||||
ggplot(df, aes(trt, outcome)) +
|
||||
geom_brick_col(aes(fill = trt)) +
|
||||
coord_brick()
|
||||
|
||||
#horizontal bars
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/coord_brick.R
|
||||
\name{coord_brick_flip}
|
||||
\alias{coord_brick_flip}
|
||||
\title{Flipped Cartesian coordinates with fixed "aspect ratio"}
|
||||
\usage{
|
||||
coord_brick_flip(xlim = NULL, ylim = NULL, expand = TRUE,
|
||||
clip = "on")
|
||||
}
|
||||
\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. X- and y- axes are flipped.
|
||||
}
|
||||
85
man/geom_brick_col.Rd
Normal file
85
man/geom_brick_col.Rd
Normal file
@@ -0,0 +1,85 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/geom_brick_col.R
|
||||
\name{geom_brick_col}
|
||||
\alias{geom_brick_col}
|
||||
\title{Bar charts with bricks}
|
||||
\usage{
|
||||
geom_brick_col(mapping = NULL, data = NULL, position = "dodge",
|
||||
two_knob = TRUE, split_bricks = TRUE, min_radius_for_text = 0.02,
|
||||
label = "brickr", label_scale = 1, ..., width = NULL,
|
||||
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
|
||||
}
|
||||
\arguments{
|
||||
\item{mapping}{Set of aesthetic mappings created by \code{\link[=aes]{aes()}} or
|
||||
\code{\link[=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[=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[=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.}
|
||||
|
||||
\item{position}{It it not recommended to use \code{position = "stack"}.}
|
||||
|
||||
\item{two_knob}{Logical. Each bar is two knobs / studs wide. When rendering many \code{x} values, set to \code{FALSE}.}
|
||||
|
||||
\item{split_bricks}{Logical. For simpler bars, do not split into individual bricks. Knobs still render.}
|
||||
|
||||
\item{min_radius_for_text}{Knob radius as a percentage of view port. If the calculated radius is lower than this value, embossed label will not appear in knobs.}
|
||||
|
||||
\item{label}{Character string to include as embossed text inside brick knobs. Maximum 6 characters.}
|
||||
|
||||
\item{label_scale}{Scale text size of label as a percentage.
|
||||
Sizing for the embossed text can be off. A best attempt at the text size is calculated from the device size. Zooming a plot in the RStudio window will not update the text size.
|
||||
If the automated size doesn't look correct after rendering the chart, use this scale.}
|
||||
|
||||
\item{...}{Other arguments passed on to \code{\link[=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{width}{Bar width. By default, set to 90\% of the resolution of the data.}
|
||||
|
||||
\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[=borders]{borders()}}.}
|
||||
}
|
||||
\description{
|
||||
\code{geom_brick_col()} is the \code{brickr} version of \code{ggplot2::geom_col()}.
|
||||
Bar height is determined by values in the data using the \code{y} aesthetic. With the exception of \code{fill}, aesthetics available in \code{ggplot2::geom_col()} are generally not enabled here.
|
||||
}
|
||||
\examples{
|
||||
#geom_brick_col should be used in conjunction with other brickr charting functions, especially coord_brick.
|
||||
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
|
||||
ggplot(df, aes(trt, outcome)) +
|
||||
geom_brick_col() +
|
||||
coord_brick()
|
||||
|
||||
#For official LEGO colors, use with scale_fill_brick and theme_brick.
|
||||
ggplot(df, aes(trt, outcome)) +
|
||||
geom_brick_col(aes(fill = trt)) +
|
||||
scale_fill_brick() +
|
||||
coord_brick() +
|
||||
theme_brick()
|
||||
|
||||
}
|
||||
@@ -28,8 +28,7 @@ data. All objects will be fortified to produce a data frame. See
|
||||
|
||||
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)}).}
|
||||
will be used as the layer data.}
|
||||
|
||||
\item{stat}{The statistical transformation to use on the data for this
|
||||
layer, as a string.}
|
||||
@@ -42,8 +41,6 @@ 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{linejoin}{Line join style (round, mitre, bevel).}
|
||||
|
||||
\item{na.rm}{If \code{FALSE}, the default, missing values are removed with
|
||||
a warning. If \code{TRUE}, missing values are silently removed.}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/draw_key.R, R/geom_brick.R, R/geom_brick_col.R
|
||||
% Please edit documentation in R/draw_key.R, R/geom_brick.R
|
||||
\name{draw_key_brick}
|
||||
\alias{draw_key_brick}
|
||||
\alias{geom_brick_rect}
|
||||
\alias{geom_brick_col}
|
||||
\title{ggplot2 Bar Charts as Bricks}
|
||||
\usage{
|
||||
draw_key_brick(data, params, size)
|
||||
@@ -12,11 +11,6 @@ geom_brick_rect(mapping = NULL, data = NULL, stat = "identity",
|
||||
position = "identity", ..., label = "LEGO",
|
||||
simplified_threshold = 24 * 24, linejoin = "mitre", na.rm = FALSE,
|
||||
show.legend = NA, inherit.aes = TRUE)
|
||||
|
||||
geom_brick_col(mapping = NULL, data = NULL, position = "dodge",
|
||||
two_knob = TRUE, split_bricks = TRUE, min_radius_for_text = 0.02,
|
||||
..., width = NULL, na.rm = FALSE, show.legend = NA,
|
||||
inherit.aes = TRUE)
|
||||
}
|
||||
\description{
|
||||
\code{geom_rect}, except bars look like LEGO(R) bricks.
|
||||
|
||||
@@ -2,49 +2,75 @@
|
||||
% Please edit documentation in R/scale_brick.R
|
||||
\name{scale_fill_brick}
|
||||
\alias{scale_fill_brick}
|
||||
\title{Create your own discrete scale}
|
||||
\title{Color scales for bricks}
|
||||
\usage{
|
||||
scale_fill_brick(brick_theme = "classic", ...)
|
||||
}
|
||||
\arguments{
|
||||
\item{brick_theme}{Color options for brickr.}
|
||||
\item{brick_theme}{Color palette for bricks. Same as \code{brickr::theme_brick()}. Options include:
|
||||
\code{ c("classic", "hp", "sw_light", "sw_dark", "friends", "elves",
|
||||
"ninja", "classy", "city", "ocean", "movie", "space",
|
||||
"jurassic", "duplo", "superhero",
|
||||
"rainbow7", "rainbow13", "doublerainbow", "blue")}.}
|
||||
|
||||
\item{...}{Other parameters from ggplots::scale_fill_manual().}
|
||||
\item{...}{Arguments passed on to \code{discrete_scale}
|
||||
\describe{
|
||||
\item{palette}{A palette function that when called with a single integer
|
||||
argument (the number of levels in the scale) returns the values that
|
||||
they should take.}
|
||||
\item{breaks}{One of:
|
||||
\itemize{
|
||||
\item \code{NULL} for no breaks
|
||||
\item \code{waiver()} for the default breaks computed by the
|
||||
transformation object
|
||||
\item A character vector of breaks
|
||||
\item A function that takes the limits as input and returns breaks
|
||||
as output
|
||||
}}
|
||||
\item{limits}{A character vector that defines possible values of the scale
|
||||
and their order.}
|
||||
\item{drop}{Should unused factor levels be omitted from the scale?
|
||||
The default, \code{TRUE}, uses the levels that appear in the data;
|
||||
\code{FALSE} uses all the levels in the factor.}
|
||||
\item{na.translate}{Unlike continuous scales, discrete scales can easily show
|
||||
missing values, and do so by default. If you want to remove missing values
|
||||
from a discrete scale, specify \code{na.translate = FALSE}.}
|
||||
\item{na.value}{If \code{na.translate = TRUE}, what value aesthetic
|
||||
value should missing be displayed as? Does not apply to position scales
|
||||
where \code{NA} is always placed at the far right.}
|
||||
\item{scale_name}{The name of the scale}
|
||||
\item{name}{The name of the scale. Used as the axis or legend title. If
|
||||
\code{waiver()}, the default, the name of the scale is taken from the first
|
||||
mapping used for that aesthetic. If \code{NULL}, the legend title will be
|
||||
omitted.}
|
||||
\item{labels}{One of:
|
||||
\itemize{
|
||||
\item \code{NULL} for no labels
|
||||
\item \code{waiver()} for the default labels computed by the
|
||||
transformation object
|
||||
\item A character vector giving labels (must be same length as \code{breaks})
|
||||
\item A function that takes the breaks as input and returns labels
|
||||
as output
|
||||
}}
|
||||
\item{guide}{A function used to create a guide or its name. See
|
||||
\code{\link[=guides]{guides()}} for more info.}
|
||||
\item{super}{The super class to use for the constructed scale}
|
||||
}}
|
||||
}
|
||||
\description{
|
||||
These functions allow you to specify your own set of mappings from levels in the
|
||||
data to aesthetic values.
|
||||
brickr counterpart to \code{ggplot2::scale_fill_discrete()} to map bar colors to the palette of LEGO mold colors.
|
||||
}
|
||||
\details{
|
||||
The functions \code{scale_colour_manual()}, \code{scale_fill_manual()}, \code{scale_size_manual()},
|
||||
etc. work on the aesthetics specified in the scale name: \code{colour}, \code{fill}, \code{size},
|
||||
etc. However, the functions \code{scale_colour_manual()} and \code{scale_fill_manual()} also
|
||||
have an optional \code{aesthetics} argument that can be used to define both \code{colour} and
|
||||
\code{fill} aesthetic mappings via a single function call (see examples). The function
|
||||
\code{scale_discrete_manual()} is a generic scale that can work with any aesthetic or set
|
||||
of aesthetics provided via the \code{aesthetics} argument.
|
||||
}
|
||||
\section{Color Blindness}{
|
||||
|
||||
Many color palettes derived from RGB combinations (like the "rainbow" color
|
||||
palette) are not suitable to support all viewers, especially those with
|
||||
color vision deficiencies. Using \code{viridis} type, which is perceptually
|
||||
uniform in both colour and black-and-white display is an easy option to
|
||||
ensure good perceptive properties of your visulizations.
|
||||
The colorspace package offers functionalities
|
||||
\itemize{
|
||||
\item to generate color palettes with good perceptive properties,
|
||||
\item to analyse a given color palette, like emulating color blindness,
|
||||
\item and to modify a given color palette for better perceptivity.
|
||||
}
|
||||
|
||||
For more information on color vision deficiencies and suitable color choices
|
||||
see the \href{https://arxiv.org/abs/1903.06490}{paper on the colorspace package}
|
||||
and references therein.
|
||||
}
|
||||
|
||||
\examples{
|
||||
p <- ggplot(mtcars, aes(mpg, wt)) +
|
||||
geom_point(aes(colour = factor(cyl)))
|
||||
p + scale_colour_manual(values = c("red", "blue", "green"))
|
||||
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
|
||||
p <- ggplot(df, aes(trt, outcome)) +
|
||||
geom_brick_col(aes(fill = trt)) +
|
||||
coord_brick()
|
||||
|
||||
p + scale_fill_brick()
|
||||
|
||||
#Select a brick_theme and use with theme_brick()
|
||||
tm <- "hp"
|
||||
p +
|
||||
scale_fill_brick(tm) +
|
||||
theme_brick(tm)
|
||||
}
|
||||
|
||||
@@ -2,16 +2,10 @@
|
||||
% Please edit documentation in R/theme_brick.R
|
||||
\name{theme_brick}
|
||||
\alias{theme_brick}
|
||||
\title{Modify components of a theme}
|
||||
\title{Brick color themes}
|
||||
\usage{
|
||||
theme_brick(brick_theme = "classic")
|
||||
}
|
||||
\description{
|
||||
Themes are a powerful way to customize the non-data components of your
|
||||
plots: i.e. titles, labels, fonts, background, gridlines, and legends.
|
||||
Themes can be used to give plots a consistent customized look.
|
||||
Modify a single plot's theme using \code{theme()}; see \code{\link[=theme_update]{theme_update()}} if
|
||||
you want modify the active theme, to affect all subsequent plots. Theme
|
||||
elements are documented together according to inheritance, read more
|
||||
about theme inheritance below.
|
||||
Brick color themes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user