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

  • SEARCH
  • Home
  • 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 4236100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:35:32+00:00 2026-05-21T02:35:32+00:00

I am trying to produce a .png file with an R plot. This works

  • 0

I am trying to produce a .png file with an R plot. This works great:

png(file="hello.png", width=1000, height=800)

# Lots and lots of plotting. Long code. Very slow.
plot(x=c(1, 2, 3), y=c(4, 6, 5))

dev.off()

Now how can I get a thumbnail of hello.png directly from R?

  • 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-05-21T02:35:33+00:00Added an answer on May 21, 2026 at 2:35 am

    I’m not sure how this will scale to your real application and don’t have much experience with the png library, but this worked reasonably quick on my test cases. You need to specify the name of the PNG file you want to make a thumbnail of and the height / width of that thumbnail. By default, it will save a thumbnail in the same directory with thumb_ prepended to the file name.

    makeThumb <- function(file, height, width) {
      require(png)
      img <- readPNG(file)
    
      png(file = paste("thumb", file, sep = "_"), height = height, width = width)
        par(mar=c(0,0,0,0), xaxs="i", yaxs="i", ann=FALSE)
        plot(1:2, type='n', xaxt = "n", yaxt = "n", xlab = "", ylab = "")
        lim <- par()
        rasterImage(img, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4])
      dev.off()
    }
    

    Let me know if this works for you. The function works well with lapply to operate on a large number of files in a directory at once as well: lapply(listOfFiles, makeThumb, height = 200, width = 200).

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

Sidebar

Related Questions

I am trying to produce a scatter plot that has two different y-axes and
I'm trying to produce this XML statement (minus the formatting and specific values): <swatchcolor
I'm trying to produce random integers (uniformly distributed). I found this snippet on an
I have a problem on my mac when trying in R to produce png
In this code example, i am trying to produce the following view hierarchy Window
I'm trying to produce a shoes layout like the following: example GUI layout http://csclub.uwaterloo.ca/~s3weber/gui.png
I'm trying to setup the below emblem-important.png so when you click this item, it'll
I'm trying to load a certificate and a png file into a char* in
I am trying to produce a drawing of a 3D sphere within a canvas
I am trying to produce a report which identifies client cases which were open

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.