0

I have a little problem with RStudio and the automatic export options. I have a big script which creates a lot of plots and I use the following code for this.

for(i in 1:2){
  if(i == 1)
    pdf(file="/home/steffen/Downloads/test.pdf",width=12,height=8)![enter image description here][1]
  plot(1:3);
  if(i == 1)
    dev.off()
}

enter image description here

This works quite well, but I have to use the plots in Microsoft Word and Word does not really like to include PDFs ... so it would be great if I could create pngs instead. I tried 'convert' command in linux but the result is that die pdf which is about 20kb is afterwords about 1MB as png and the quality is not as expected. My script is the following:

for i in "$@"; do
  dst="${i%pdf}png"
  convert -density 1000x1000 -resize 3000x3000 -quality 95 "$i" "./png/$dst"
done

So does anyone have a good idea how to create a png which is not so large but has a good quality.

Either directly with RStudio or afterwords a conversation an automatic conversation.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
steffenmauch
  • 353
  • 5
  • 16
  • 1
    Try `?Devices` and then `?png`. – Josh O'Brien Dec 04 '12 at 08:38
  • 1
    As others said, use png(). Or if you must convert from PDF to PNG, see this SO question and answer for better quality: http://stackoverflow.com/questions/2869908/convert-pdf-to-png-using-imagemagick. -density 96 is probably what you want. – neilfws Dec 04 '12 at 08:51

1 Answers1

4

Use the png function.

png(file="path.png",width=12,height=8)
Tim
  • 13,904
  • 10
  • 69
  • 101
  • 1
    very unlikely values, as default is: `units = "px"` you would want to specify a real length like `in`,`cm`, or `mm` – Toby Sep 05 '13 at 17:02