Add collect_brick's use_bricks input to geom_brick_rect

This commit is contained in:
Ryan Timpe
2019-07-21 13:18:03 -04:00
parent 70b159de1e
commit 8e3cdbb5ca
2 changed files with 8 additions and 3 deletions
+3 -1
View File
@@ -23,7 +23,9 @@ brick_colors <- function(.names_only = FALSE){
levels = gsub(" ", "\n", lego_colors$Color))) %>%
ggplot2::ggplot(aes(x=x, y=y, group=color)) +
ggplot2::labs(title = "Brick colors available in {brickr}") +
geom_brick_rect(aes(fill = color_hex), label_scale = 0.1) +
geom_brick_rect(aes(fill = color_hex), label_scale = 0.1,
#Including the use_bricks inputs greatly increases the speed of this.
use_bricks = c("2x2")) +
ggplot2::coord_fixed(x=c(0.5, 2.5), y=c(0.5, 2.5)) +
ggplot2::scale_fill_identity() +
ggplot2::facet_wrap(~color, ncol = 9) +
+5 -2
View File
@@ -7,6 +7,7 @@ geom_brick_rect <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
label = "brickr", simplified_threshold = 24*24, label_scale = 1,
use_bricks = NULL,
linejoin = "mitre",
na.rm = FALSE,
show.legend = NA,
@@ -23,6 +24,7 @@ geom_brick_rect <- function(mapping = NULL, data = NULL,
linejoin = linejoin,
label = label,
label_scale = label_scale,
use_bricks = use_bricks,
na.rm = na.rm,
simplified_threshold = simplified_threshold,
...
@@ -53,7 +55,8 @@ GeomBrick <- ggproto("GeomBrick", Geom,
},
draw_panel = function(self, data, panel_params, coord, linejoin = "mitre",
simplified_threshold = 24*24, label_scale = 1) {
simplified_threshold = 24*24, label_scale = 1,
use_bricks = use_bricks) {
#This happens to EACH panel
if (!coord$is_linear()) {
@@ -74,7 +77,7 @@ GeomBrick <- ggproto("GeomBrick", Geom,
data$Lego_color <- data$fill
}
dat <- collect_bricks(list(Img_lego = data))$Img_bricks
dat <- collect_bricks(list(Img_lego = data), use_bricks = use_bricks)$Img_bricks
dat <- transform(dat,
PANEL = Level, Level = NULL,
fill = Lego_color)