mirror of
https://github.com/ryantimpe/brickr.git
synced 2026-01-07 06:10:56 -06:00
draw_key_brick()
Still needs a lot of documentation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
Package: brickr
|
||||
Title: Create Simulated LEGO Models from Images or Data Frames
|
||||
Version: 0.0.0.9410
|
||||
Version: 0.0.0.9415
|
||||
Authors@R:
|
||||
person(given = "Ryan",
|
||||
family = "Timpe",
|
||||
@@ -30,6 +30,7 @@ Collate:
|
||||
'bricks_to_3d.R'
|
||||
'collect_bricks.R'
|
||||
'coord_brick.R'
|
||||
'draw_key.R'
|
||||
'geom_brick.R'
|
||||
'geom_brick_col.R'
|
||||
'geom_brick_point.R'
|
||||
|
||||
@@ -16,6 +16,7 @@ export(display_bricks)
|
||||
export(display_colors)
|
||||
export(display_pieces)
|
||||
export(display_set)
|
||||
export(draw_key_brick)
|
||||
export(generate_instructions)
|
||||
export(geom_brick_col)
|
||||
export(geom_brick_point)
|
||||
|
||||
35
R/draw_key.R
Normal file
35
R/draw_key.R
Normal file
@@ -0,0 +1,35 @@
|
||||
#' @export
|
||||
#' @rdname geom_brick_rect
|
||||
draw_key_brick <- function(data, params, size) {
|
||||
|
||||
#Outline and text for dark colors
|
||||
data$color_intensity <- as.numeric(colSums(col2rgb(data$fill)))
|
||||
data$text_alpha <- ifelse(data$color_intensity < 200, 0.2, 0.2)
|
||||
data$text_col <- ifelse(data$color_intensity < 200, "#CCCCCC", "#333333")
|
||||
|
||||
test <<- data
|
||||
|
||||
grid::grobTree(
|
||||
grid::rectGrob(gp = grid::gpar(col = alpha(data$colour %||% "#333333", 0.2),
|
||||
fill = alpha(data$fill %||%
|
||||
data$colour %||% "#333333", data$alpha))),
|
||||
grid::circleGrob(0.6, 0.4, r = 5/8*(1/2),
|
||||
gp = grid::gpar(col = NA,
|
||||
fill = alpha("#333333", 0.2))),
|
||||
grid::circleGrob(0.5, 0.5, r = 5/8*(1/2),
|
||||
gp = grid::gpar(col = alpha(data$text_col, data$text_alpha),
|
||||
fill = alpha(data$fill, data$alpha))),
|
||||
grid::textGrob(
|
||||
data$label,
|
||||
0.5, 0.5,
|
||||
hjust = 0.5, vjust=0.5,
|
||||
default.units = "native",
|
||||
gp = grid::gpar(
|
||||
col = alpha(data$text_col, data$text_alpha),
|
||||
# fontsize = fs,
|
||||
cex = (3/8)*0.65,
|
||||
fontface = "bold"
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
#'
|
||||
#' `geom_rect`, except bars look like LEGO(R) bricks.
|
||||
#'
|
||||
#' @inheritParams ggplot2::geom_rect
|
||||
#' @export
|
||||
geom_brick_rect <- function(mapping = NULL, data = NULL,
|
||||
stat = "identity", position = "identity",
|
||||
|
||||
@@ -223,5 +223,5 @@ GeomBrickCol <- ggproto("GeomCol", GeomBrick,
|
||||
}
|
||||
},
|
||||
|
||||
draw_key = draw_key_polygon
|
||||
draw_key = draw_key_brick
|
||||
)
|
||||
@@ -1,66 +1,21 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/geom_brick.R, R/geom_brick_col.R
|
||||
\name{geom_brick_rect}
|
||||
% Please edit documentation in R/draw_key.R, R/geom_brick.R, R/geom_brick_col.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)
|
||||
|
||||
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 = "stack", ...,
|
||||
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. 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[=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{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.}
|
||||
|
||||
\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()}}.}
|
||||
geom_brick_col(mapping = NULL, data = NULL, position = "dodge",
|
||||
two_knob = TRUE, ..., width = NULL, na.rm = FALSE,
|
||||
show.legend = NA, inherit.aes = TRUE)
|
||||
}
|
||||
\description{
|
||||
\code{geom_rect}, except bars look like LEGO(R) bricks.
|
||||
|
||||
Reference in New Issue
Block a user