Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{brickr} Getting Started
library(brickr)
#This is a brick
brick <- data.frame(
Level="A",
X1 = rep(1,4),
X2 = rep(1,4)
)
brick %>%
bricks_from_table() %>%
display_bricks()
#There are 2 ways to change the color of the brick ----
# Change the number to the brickr color ID # from display_colors()
brick <- data.frame(
Level="A",
X1 = rep(6,4),
X2 = rep(6,4)
)
brick %>%
bricks_from_table() %>%
display_bricks()
# -or -
# Provide a table to map values to official Color names from display_colors(.names_only=TRUE)
brick <- data.frame(
Level="A",
X1 = rep(1,4),
X2 = rep(1,4)
)
brick_colors <- data.frame(
.value = 1,
Color = "Bright blue"
)
brick %>%
bricks_from_table(brick_colors) %>%
display_bricks()
#You can stack 2 bricks ----
brick <- data.frame(
Level= c(rep("A",4), rep("B",4)),
X1 = rep(1,4),
X2 = rep(1,4)
)
brick %>%
bricks_from_table(brick_colors) %>%
display_bricks()
#You can stack many bricks ----
brick <- data.frame(
Level="A",
X1 = rep(1,4),
X2 = rep(1,4)
)
1:10 %>%
purrr::map_df(~dplyr::mutate(brick, Level = LETTERS[.x])) %>%
bricks_from_table(brick_colors) %>%
display_bricks()
#... And they can all be different colors ----
1:10 %>%
purrr::map_df(~dplyr::mutate(brick, Level = LETTERS[.x], X1 = .x, X2 = .x)) %>%
bricks_from_table() %>%
display_bricks()
# Using tibble::tribble() makes it a bit easier to design
# Use 0 for empty space
my_first_model <- tibble::tribble(
~Level, ~X1, ~X2, ~X3, ~x4, ~x5, ~X6, ~x7, ~x8,
"A", 1, 1, 1, 0, 1, 1, 1, 1,
"A", 1, 0, 0, 0, 0, 0, 0, 1,
"A", 1, 0, 0, 0, 0, 0, 0, 1,
"A", 1, 1, 1, 1, 1, 1, 1, 1,
"B", 1, 0, 1, 0, 1, 1, 0, 1,
"B", 1, 0, 0, 0, 0, 0, 0, 1,
"B", 1, 0, 0, 0, 0, 0, 0, 1,
"B", 1, 0, 1, 0, 0, 1, 0, 1,
"C", 1, 1, 1, 1, 1, 1, 1, 1,
"C", 1, 0, 0, 0, 0, 0, 0, 1,
"C", 1, 0, 0, 0, 0, 0, 0, 1,
"C", 1, 1, 1, 1, 1, 1, 1, 1,
"D", 2, 2, 2, 2, 2, 2, 2, 2,
"D", 1, 0, 0, 0, 0, 0, 0, 1,
"D", 1, 0, 0, 0, 0, 0, 0, 1,
"D", 2, 2, 2, 2, 2, 2, 2, 2,
"E", 0, 0, 0, 0, 0, 0, 0, 0,
"E", 2, 2, 2, 2, 2, 2, 2, 2,
"E", 2, 2, 2, 2, 2, 2, 2, 2,
"E", 0, 0, 0, 0, 0, 0, 0, 0
)
brick_colors <- tibble::tribble(
~`.value`, ~Color,
1, "Bright blue",
2, "Dark orange"
)
my_first_model %>%
bricks_from_table(brick_colors) %>%
display_bricks()
@BEAST-Community

This comment has been minimized.

Copy link

@BEAST-Community BEAST-Community commented Mar 22, 2019

@how to install brickr pacakge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment