+ Reply to Thread
Results 1 to 6 of 6

Thread: breaking apart multiple external plots

  1. #1
    FormerlyKnownAsRaptor
    Points: 24,227, Level: 94
    Level completed: 88%, Points required for next Level: 123
    Awards:
    Master Tagger
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    3,155
    Thanks
    882
    Thanked 544 Times in 492 Posts

    breaking apart multiple external plots



    In R I often plot multiple plots to a single file as it makes storing, accessing and viewing the visualizations easier. So I may have a multi page pdf or png of various visualizations.

    Now here's the question is there a program (probably not actually R) that can break the pdf or png up into individual pic files. ie how can I extract just one page from a pdf or png and put that pic in a latex or MS word document?

    Some may say well output them as single files, true I could dot hat but I don't want to. If you're dealing with hundreds of files it becomes a pain to open them all up and look through them in that way. I'm using inkscape to edit one pdf/png/svg file maybe it can break them apart too? Don't know.

    I'm sure I could find one on my own with a google search but people's recommendations here tend to be spot on.

    Here's the succint question(s):
    1. Is there a program/method that works with both pdf/png etc to break them apart into singular pictures for use in a write up? What is it?
    2. If not what would work for pdfs?
    3. What would work for pngs?

    One restriction the answer must be open source
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  2. #2
    TS Contributor
    Points: 6,533, Level: 52
    Level completed: 92%, Points required for next Level: 17
    Lazar's Avatar
    Location
    Sydney
    Posts
    660
    Thanks
    109
    Thanked 164 Times in 149 Posts

    Re: breaking apart multiple external plots

    inkscape will do the job. Also I save all plots from R as SVGs as this gives the most flexibility for later use.

    EDIT: I just read your post in full. Sorry. I still think inkscape can do what you want though.

  3. The Following User Says Thank You to Lazar For This Useful Post:

    trinker (08-23-2012)

  4. #3
    Bhoot
    Points: 1,275, Level: 19
    Level completed: 75%, Points required for next Level: 25

    Posts
    1,758
    Thanks
    40
    Thanked 124 Times in 106 Posts

    Re: breaking apart multiple external plots

    Hi Trinker,
    I am not sure I understand your question. "Multiple plots to a single file" does this mean that using mfrow/mfcol ( in base graphics) right? or this mean you save the figures as a page in pdf?
    In latex, there is an option for crop option(trim=) in the includegraphics ( for png file). If you wanted to specify particular page of pdf, that is also possible in includegraphics (like \includegraphics[page=n]{trpdf})

  5. #4
    FormerlyKnownAsRaptor
    Points: 24,227, Level: 94
    Level completed: 88%, Points required for next Level: 123
    Awards:
    Master Tagger
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    3,155
    Thanks
    882
    Thanked 544 Times in 492 Posts

    Re: breaking apart multiple external plots

    Good question vinux (I can't upload an example due to very limited internet access but can post code to make an example:

    Code: 
    pdf("testerooni.pdf", 8, 8)
    
    lapply(2:ncol(mtcars), function(i) {
        #dev.new()
        plot(mtcars[, 1], mtcars[, i], main=colnames(mtcars)[i])
        }
    )
    dev.off()
    Which raises another question. Why does this not produce multiple pages like the pdf does? Is multi page png possible?
    Code: 
    png("testerooni.png", 800, 800)
    
    lapply(2:ncol(mtcars), function(i) {
        #dev.new()
        plot(mtcars[, 1], mtcars[, i], main=colnames(mtcars)[i])
        }
    )
    dev.off()
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  6. #5
    Bhoot
    Points: 1,275, Level: 19
    Level completed: 75%, Points required for next Level: 25

    Posts
    1,758
    Thanks
    40
    Thanked 124 Times in 106 Posts

    Re: breaking apart multiple external plots

    as far as i know multipage is not possible in png. It may possible in gif.
    In linux, convert function can split the pdf to multiple png files

  7. #6
    Probably A Mammal
    Points: 14,448, Level: 77
    Level completed: 99%, Points required for next Level: 2
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    1,950
    Thanks
    221
    Thanked 419 Times in 387 Posts

    Re: breaking apart multiple external plots


    A png is just a single image. Usually I create an image book pdf for a given output. If I want the individual graphics, I may also run it again having it create the folder (if necessary) and storing all the images with that image book. I name the image book and folder the same. That way if they want to view them all in one document, they can view the pdf, or if they want the individual pictures, they can view the png's. The problem is setting parameters correctly as they come out with different qualities. I'm doing some pretty big plots (hundreds of thousands of points) and it crashed Adobe! I suspect the pdf was saving them as SVG, which makes sense, but can be a pain because it has to draw them whenever you move the document ... and that takes forever!!

    Is there a way to produce "low quality" SVGs?? lol

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats