Skip to main content
add info about multi-page PDF
Source Link

For R users, the package grImport (on CRAN) can import vector graphics and convert them into objects that R can interpret. It assumes that one can convert PDF (or other vector format of interest) to PostScript format. This can be done for example with Inkscape: import (File > Import) your PDF page with your figure into Inkspace and File > Save As > Save as type: > PostScript *.ps. Once you have your *.ps file fallow the grImport vignette Importing Vector Graphics, more relevant being section '4.1. Scraping data from images'.

You will need ghostscript on your Operating System - try to download it from here.

Note, if you run somehow into ghostscript error 'status 127' when you call grImport::PostScriptTrace, then fallow the recommendation from here, which says to manually set the path to ghostscript on your machine.

Here is some sample R code to import PostScript file into R:

install.packages("grImport")
require(grImport)
# if you get the ghostscript error 'status 127' then set the path to ghostscript, e.g.:
Sys.setenv(R_GSCMD = normalizePath("C:/Program Files/gs/gs9.22/bin/gswin64c.exe")) 
PostScriptTrace(file = "graph.ps", outfilename = "graph.ps.xml")
my_fig <- readPicture(rgmlFile = "graph.ps.xml")
grid.picture(my_fig)

Note, if your graph is on a page in a multi page PDF file, then you can split the multi-page document with PDFTK builder. Import your one page PDF file in Ikscape and delete any extra elements (extra text, extra graph elements). This wil ease your work in R when trying to catch the coordinates of the graph elements you are interested in.

For R users, the package grImport (on CRAN) can import vector graphics and convert them into objects that R can interpret. It assumes that one can convert PDF (or other format of interest) to PostScript format. This can be done for example with Inkscape: import (File > Import) your PDF page with your figure into Inkspace and File > Save As > Save as type: > PostScript *.ps. Once you have your *.ps file fallow the grImport vignette Importing Vector Graphics, more relevant being section '4.1. Scraping data from images'.

You will need ghostscript on your Operating System - try to download it from here.

Note, if you run somehow into ghostscript error 'status 127' when you call grImport::PostScriptTrace, then fallow the recommendation from here, which says to manually set the path to ghostscript on your machine.

Here is some sample R code to import PostScript file into R:

install.packages("grImport")
require(grImport)
# if you get the ghostscript error 'status 127' then set the path to ghostscript, e.g.:
Sys.setenv(R_GSCMD = normalizePath("C:/Program Files/gs/gs9.22/bin/gswin64c.exe")) 
PostScriptTrace(file = "graph.ps", outfilename = "graph.ps.xml")
my_fig <- readPicture(rgmlFile = "graph.ps.xml")
grid.picture(my_fig)

For R users, the package grImport (on CRAN) can import vector graphics and convert them into objects that R can interpret. It assumes that one can convert PDF (or other vector format of interest) to PostScript format. This can be done for example with Inkscape: import (File > Import) your PDF page with your figure into Inkspace and File > Save As > Save as type: > PostScript *.ps. Once you have your *.ps file fallow the grImport vignette Importing Vector Graphics, more relevant being section '4.1. Scraping data from images'.

You will need ghostscript on your Operating System - try to download it from here.

Note, if you run somehow into ghostscript error 'status 127' when you call grImport::PostScriptTrace, then fallow the recommendation from here, which says to manually set the path to ghostscript on your machine.

Here is some sample R code to import PostScript file into R:

install.packages("grImport")
require(grImport)
# if you get the ghostscript error 'status 127' then set the path to ghostscript, e.g.:
Sys.setenv(R_GSCMD = normalizePath("C:/Program Files/gs/gs9.22/bin/gswin64c.exe")) 
PostScriptTrace(file = "graph.ps", outfilename = "graph.ps.xml")
my_fig <- readPicture(rgmlFile = "graph.ps.xml")
grid.picture(my_fig)

Note, if your graph is on a page in a multi page PDF file, then you can split the multi-page document with PDFTK builder. Import your one page PDF file in Ikscape and delete any extra elements (extra text, extra graph elements). This wil ease your work in R when trying to catch the coordinates of the graph elements you are interested in.

Source Link

For R users, the package grImport (on CRAN) can import vector graphics and convert them into objects that R can interpret. It assumes that one can convert PDF (or other format of interest) to PostScript format. This can be done for example with Inkscape: import (File > Import) your PDF page with your figure into Inkspace and File > Save As > Save as type: > PostScript *.ps. Once you have your *.ps file fallow the grImport vignette Importing Vector Graphics, more relevant being section '4.1. Scraping data from images'.

You will need ghostscript on your Operating System - try to download it from here.

Note, if you run somehow into ghostscript error 'status 127' when you call grImport::PostScriptTrace, then fallow the recommendation from here, which says to manually set the path to ghostscript on your machine.

Here is some sample R code to import PostScript file into R:

install.packages("grImport")
require(grImport)
# if you get the ghostscript error 'status 127' then set the path to ghostscript, e.g.:
Sys.setenv(R_GSCMD = normalizePath("C:/Program Files/gs/gs9.22/bin/gswin64c.exe")) 
PostScriptTrace(file = "graph.ps", outfilename = "graph.ps.xml")
my_fig <- readPicture(rgmlFile = "graph.ps.xml")
grid.picture(my_fig)
Post Made Community Wiki by Valentin_Ștefan