-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f3a9f8
commit b67790b
Showing
8 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: wallis | ||
Title: Room squares in R | ||
Version: 0.0.0.9000 | ||
Version: 0.0.0.9001 | ||
Authors@R: | ||
person("Matthew", "Henderson", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0001-7949-8208")) | ||
|
@@ -10,5 +10,8 @@ Encoding: UTF-8 | |
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.1 | ||
Imports: | ||
dplyr, | ||
ggplot2, | ||
purrr, | ||
tibble, | ||
tidyr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(plot_room_square) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#' Horizontal grid lines | ||
#' | ||
#' @param n_rows Number of rows. | ||
#' @param n_cols Number of columns. | ||
#' | ||
#' @return A tibble with columns x, y, xend and yend. | ||
horiz_lines <- function(n_rows, n_cols) { | ||
tibble::tibble( | ||
x = rep(0, n_rows + 1) + .5, | ||
y = 0:n_rows + .5, | ||
xend = rep(n_cols, n_rows + 1) + .5, | ||
yend = 0:n_rows + .5 | ||
) | ||
} | ||
|
||
#' Vertical grid lines | ||
#' | ||
#' @param n_rows Number of rows. | ||
#' @param n_cols Number of columns. | ||
#' | ||
#' @return A tibble with columns x, y, xend and yend. | ||
vertical_lines <- function(n_rows, n_cols) { | ||
tibble::tibble( | ||
x = 0:n_cols + .5, | ||
y = rep(0, n_cols + 1) + .5, | ||
xend = 0:n_cols + .5, | ||
yend = rep(n_rows, n_cols + 1) + .5 | ||
) | ||
} | ||
|
||
#' Horizontal and vertical grid lines | ||
#' | ||
#' @param n_rows Number of rows. | ||
#' @param n_cols Number of columns. | ||
#' | ||
#' @return A tibble with columns x, y, xend and yend. | ||
grid_lines <- function(n_rows, n_cols) { | ||
dplyr::bind_rows( | ||
horiz_lines(n_rows, n_cols), | ||
vertical_lines(n_rows, n_cols) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Plot a Room square | ||
#' | ||
#' @param R A Room square. | ||
#' | ||
#' @return A ggplot plot of Room square R | ||
#' @export | ||
plot_room_square <- function(R) { | ||
|
||
n <- max(R$col) + 1 | ||
|
||
ggplot2::ggplot(data = R, ggplot2::aes(col, row)) + | ||
ggplot2::geom_tile(data = R |> dplyr::filter(!is.na(first)), ggplot2::aes(fill = fill)) + | ||
ggplot2::geom_segment(data = grid_lines(n - 1, n - 1), ggplot2::aes(x = x, y = y, xend = xend, yend = yend), linewidth = .1) + | ||
ggplot2::geom_text(data = R |> dplyr::filter(!is.na(first)), ggplot2::aes(label = paste(first, second, sep = ","))) + | ||
ggplot2::scale_y_reverse() + | ||
ggplot2::coord_fixed() + | ||
ggplot2::theme_void() + | ||
ggplot2::theme( | ||
legend.position = "none" | ||
) + | ||
ggplot2::scale_fill_gradient(limits = c(0, choose(n, 2)), low = "white", high = "blue") | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.