Skip to content

Comments

as.data.frame.maze() to help plot with {ggplot2}#4

Open
trevorld wants to merge 3 commits intokstreet13:mainfrom
trevorld:plot-with-ggplot2
Open

as.data.frame.maze() to help plot with {ggplot2}#4
trevorld wants to merge 3 commits intokstreet13:mainfrom
trevorld:plot-with-ggplot2

Conversation

@trevorld
Copy link

@trevorld trevorld commented May 10, 2024

  • Adds a as.data.frame.maze() method to help plot with {ggplot2} Can you plot mazes with ggplot2? #1
  • Updates {roxygen2} settings to allow markdown e.g. can now use [name_of_function()] to create a cross-reference to name_of_function and `code` to generate \code{code} etc.
  • Code example:
x <- maze(12L, 12L)
dfw <- as.data.frame(x, walls = TRUE)
dfs <- as.data.frame(x, start = "top", end = "bottom")
if (require("ggplot2", quietly = TRUE)) {
   ggplot(dfw, aes(x, y)) + geom_tile() + coord_equal() + theme_void() + 
   geom_path(aes(x=x, y=y), colour = "red", linewidth = 2, data = dfs)
}

image

@trevorld
Copy link
Author

Not finished yet since I still plan to add support for method = "geom_segment" but currently provides a working proof of concept.

@trevorld trevorld force-pushed the plot-with-ggplot2 branch 3 times, most recently from 4897dcc to ef2418c Compare May 11, 2024 22:48
@trevorld trevorld marked this pull request as ready for review May 11, 2024 22:51
@trevorld
Copy link
Author

  • @kstreet13 , this PR for Can you plot mazes with ggplot2? #1 should be ready for review
  • In tests/testthat/test-ggplot2.R I added five {ggplot2} snapshot tests plus I added one example in the docs for as.data.frame.maze()
  • I also re-organized the existing plotting and printing tests as "snapshot" tests
  • I also found it necessary to add a new by argument to solve_maze()
  • It would be cool to also add support for geom_polygon() but i think that is beyond the scope of this PR

@trevorld trevorld force-pushed the plot-with-ggplot2 branch from ef2418c to 662e3ca Compare May 11, 2024 23:04
This was referenced May 12, 2024
@trevorld
Copy link
Author

Gentle ping...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant