As the doctor gone rogue

April 30, 2010

Image processing in R — Convert EPS to PDF and others

Filed under: bash, genetics, R — Tags: , , , — hypotheses @ 1:53 am

I do a lot of plots and graphs in R, and I found that most fonts will look disproportionate if I originally save the graphic output from R using a function such as png(). So the solution I have till now is to save all of my plots using


postscript("file",paper="letter")
#as I normally want the plot to be in the size of most paper used to print here in the US
#by default the paper size is "A4" though.

Then, the next problem seems to be how do I convert these EPS files into PDF or other format.On Linux, so far my solution seems to be using ImageMagick,

convert

. However, on OsX, if you don’t want to install ImageMagick, they already have a command built-in.

Through a series of these command, you will convert your file into a subfolder with the appropriate extension.


#echo *.eps | xargs -n1 pstopdf && mkdir png; sips -s format png *.pdf --out png/
<pre>echo *.eps | xargs -n1 pstopdf && mkdir png; sips -s format png *.pdf --out png</pre>
# "YOU NEED TO GET RID OF THE / AT THE END TO AVOID ERROR ABOUT DIRECTORY NOT FOUND"

Although you will get a warning that the extension has been change to png, look inside “png” directory, and you will find all your files inside neatly converted to the format you want. You can use

sips

to convert to jpeg or other format as well.

Advertisements

Create a free website or blog at WordPress.com.