1

So I have tried everything I could think of, and after a few days of searching, I resort to asking here.

I wrote a maze solver in c++, it takes a png image, reads it as binary data, and then solves it. the final output of this solving stage is a matrix with all values set to 0 (walls and unexplored vertices of the maze), except the relevant path. R reads this matrix through Rcpp.

My algorithm itself is quite fast, solving a 10K X 10K maze I found online (weighs 127 megabytes of 16 bit integers) in 0.7 seconds, it also solved a 30k x 30k maze which is the largest I managed to load into memory without Rstudio crashing. (By saying solved, I mean that the output is an ordered sequence of all (x,y) coordinates on the path from the start to the exit).

Now the thing is that I want to look at this plot, preferably through something like a 2d heatmap plot, something which i have done on smaller mazes, but with this size of maze - every library I tried to plot with, just crashed my client. So the question is, is there any way for me to plot a 10K x 10K 2d heatmap in R? (don't mind having it cropped when I zoom out.)

Example code:

library(plotly)
mat = matrix(sample(0:1,100000000,replace = T),10000,10000)
plot_ly(z =~ mat, type = "heatmap")
dvd280
  • 876
  • 6
  • 11
  • Please add code that you have tried, saying "every library I tried to plot with, just crashed my client" doesn't help us to help. Also, please look at this question https://stackoverflow.com/questions/52889540/speed-up-rendering-of-large-heatmap-from-ggplot-in-r – pogibas Jun 06 '20 at 08:27
  • @PoGibas I guess I thought the problem was so simple to recreate that no example would be required. Added example code. – dvd280 Jun 06 '20 at 08:51
  • 2
    Maybe chunk the matrix `n` rows at a time, plot those, and then stitch those plots together externally? (Or even just chunk into largest possible submatrices.) – Dunois Jun 06 '20 at 09:20
  • Have you considered sparse matrices? I can image that from the parametrisation of triplet formatted sparse matrices it is quite easy to plot the solution path. I would recommend the `Matrix` package for this. – teunbrand Jun 06 '20 at 16:42
  • Try plotting it as a pixel matrix, rather than with `ggplot`. [See the examples here](https://stackoverflow.com/questions/5638462/r-image-of-a-pixel-matrix) – chemdork123 Jun 07 '20 at 06:02
  • It will probably still take quite some time to actually render the image though, considering the size. – chemdork123 Jun 07 '20 at 06:07

0 Answers0