Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:30:52+00:00 2026-06-09T07:30:52+00:00

I’m trying to plot a large matrix (8,000 x 8,000) as a raster image

  • 0

I’m trying to plot a large matrix (8,000 x 8,000) as a raster image in R. Unfortunately this requires too much memory for my 32-bit OS, so I’m plotting the data as two (4000 x 8000) images before recombining them.

I’ve looked at a lot of packages, and I’ve found no suitable function. I know images are imported as S4 objects with the colours stored in an array, implying that there should be a way to combine them, but I can’t figure it out. Does anyone know how to do this in R?
Thanks

Edit:

The data is stored in 8000 csv files, with file1 corresponding to the 1st row of the matrix, file2 to the second…

example code

# get the name of each matrix-row file
# each file is a vector of length 8000, each filei corresponding to matrix row i 

a <- list.files()

for(i in 1:4000){

     # read the data into R, and combine it with the other rows

     matrixRow <- read.table(a[i])
     matrixToPlot <- rbind(matrixToPlot, matrixRow)   

 }


 png("test", 4000, 4000)
     rasterImage(as.raster(matrixToPlot))
 graphics.off()
 ## identical code for matrix-row 4001, 4002, ...8000
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:30:54+00:00Added an answer on June 9, 2026 at 7:30 am

    I tried the following while eyeing the memory on my system monitor, and it stays below 3 Gb the whole time:

        A <- matrix(rnorm(8000*8000),ncol = 8000)
        print(object.size(A),units = "Mb") # 488.3 Mb
        gc() # remove wasted mem (something I don't fully understand)
    
        # open a plot of appropriate dimensions- scale to your case
        plot(NULL, type = "n", xlim = c(0, 8001), ylim = c(0, 8000))
        # add chunks of the image a bit at a time, removing waste memory at each chunk
        for (m in 1:4){
          for (n in 1:4){
            image(x = (m * 2000 - 2000):(m * 2000 - 1) + .5, # pixels are centered..
                  y = (n * 2000 - 2000):(n * 2000 - 1) + .5, 
                  t(A[(m * 2000 - 1999):(m * 2000), (n * 2000 - 1999):(n * 2000)]), 
                  useRaster = TRUE, # this is key
                  add = TRUE)     
            gc() # my naive guess is that this keeps wasted mem from building up
          }
        }
    

    this gets the thing plotted in window about as economically as I can think of. You could do the same thing by only having parts of A at a time in memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.