diff --git a/R/plot_room_square.R b/R/plot_room_square.R index f5b3ba3..dfe64cf 100644 --- a/R/plot_room_square.R +++ b/R/plot_room_square.R @@ -1,9 +1,6 @@ plot_room_square <- function(R) { - - n <- max(R$col) + 1 - nf <- n_filled_cells(R) - v <- volume(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 = visit)) + @@ -16,10 +13,20 @@ plot_room_square <- function(R) { ggplot2::theme( legend.position = "none" ) + - ggplot2::scale_fill_gradient(limits = c(0, choose(n, 2)), low = "white", high = "blue") + + ggplot2::scale_fill_gradient(limits = c(0, choose(n, 2)), low = "white", high = "blue") +} + +plot_room_square_labs <- function(R) { + + n <- max(R$col) + 1 + + nf <- n_filled_cells(R) + v <- volume(R) + + plot_room_square(R) + ggplot2::labs( - title = glue::glue("A maximal partial Room square of order {n}"), - subtitle = glue::glue("Number of filled cells: {nf}, Volume: {v}.") - ) + caption = glue::glue("Order: {n}\nFilled cells: {nf}\nVolume: {v}") + ) + + ggplot2::theme(plot.caption = ggplot2::element_text(hjust = 0)) } \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index e6d57ae..9c2edb3 100644 --- a/README.Rmd +++ b/README.Rmd @@ -4,6 +4,7 @@ author: Matthew Henderson output: github_document: toc: yes + toc_depth: 1 html_document: toc: yes editor_options: @@ -69,8 +70,8 @@ of being a partial Room square will not be violated. ```{r greedy1_example_plot} -R <- greedy1(8) -plot_room_square(R) +R <- greedy1(6) +plot_room_square_labs(R) ``` In this plot colour represents the order in which cells were filled. @@ -81,6 +82,23 @@ The cells were filled in order from lightest to darkest. is_maximal_proom(R) ``` +## A few examples of maximal partial Room squares constructed with greedy1 + +```{r greedy1_examples_1, echo=FALSE} +library(patchwork) + +R1 <- greedy1(8) +R2 <- greedy1(10) + +(plot_room_square_labs(R1) + plot_room_square_labs(R2)) +``` + +```{r greedy1_examples_2, echo=FALSE} +R3 <- greedy1(12) + +plot_room_square_labs(R3) +``` + # II: greedy2 `greedy2` @@ -91,7 +109,7 @@ Room square are not violated. ```{r greedy2_example_plot} R <- greedy2(8) -plot_room_square(R) +plot_room_square_labs(R) ``` Again colour represents order of filling, proceeding from lightest to darkest. @@ -101,4 +119,19 @@ Again colour represents order of filling, proceeding from lightest to darkest. is_maximal_proom(R) ``` +## A few examples of maximal partial Room squares constructed with greedy2 + +```{r greedy2_examples_1, echo=FALSE, fig.cap="Put a caption here"} +R1 <- greedy2(8) +R2 <- greedy2(10) + +(plot_room_square_labs(R1) + plot_room_square_labs(R2)) +``` + +```{r greedy2_examples_2, echo=FALSE} +R3 <- greedy2(12) + +plot_room_square_labs(R3) +``` + # References \ No newline at end of file diff --git a/README.md b/README.md index e7fab32..8c48bf8 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ available pair such that the conditions of being a partial Room square will not be violated. ``` r -R <- greedy1(8) -plot_room_square(R) +R <- greedy1(6) +plot_room_square_labs(R) ``` ![](figure/greedy1_example_plot-1.png) @@ -33,6 +33,12 @@ is_maximal_proom(R) #> [1] TRUE ``` +## A few examples of maximal partial Room squares constructed with greedy1 + +![](figure/greedy1_examples_1-1.png) + +![](figure/greedy1_examples_2-1.png) + # II: greedy2 `greedy2` iterates through all pairs in order placing the next pair in @@ -41,7 +47,7 @@ Room square are not violated. ``` r R <- greedy2(8) -plot_room_square(R) +plot_room_square_labs(R) ``` ![](figure/greedy2_example_plot-1.png) @@ -55,6 +61,12 @@ is_maximal_proom(R) #> [1] TRUE ``` +## A few examples of maximal partial Room squares constructed with greedy2 + +![Put a caption here](figure/greedy2_examples_1-1.png) + +![](figure/greedy2_examples_2-1.png) + # References