I use R for producing some graphics (with R base). Thereafter to better adjust the R graphics to use in LaTex I export the R plots with the tikzDevice library. Something like, e.g.: tikz('sk0.tex', width = 3, height = 4)

Recently, I started using pstricks (LaTex) and I wonder if there's a way to export R plots to the pstricks format?

Do you know if that is possible? or make sense?

  • 1
    Interesting question. I don't think there is a library, but maybe there is and I didn't look long enough. A variation of this is possible, i.e., create a PSTricks graphic using PSTricks commands, but have the data values, axis range etc. supplied by R (see stackoverflow.com/questions/67894851/…). Of course this means you are limited by the types of graphs that PSTricks can create natively.
    – Marijn
    Aug 30, 2022 at 12:51
  • 1
    I do not have the answer, but I recommend to separate the generation of the data (e.g. R, Matlab, Mathematica, C++, whatever) with the graph formatting (in LaTeX). That would mean exporting the data in a txt file (or equivalent) and the using pgfplots (or pstricks) to read these files.
    – anderstood
    Aug 30, 2022 at 12:52
  • @anderstood I don't know how much of an R user you are, but the capabilities of R's ggplot2 are a much more practical choice than using pgfplots in my experience. If you use LuaLaTeX then font matching (one of the purported advantages of using TikZ to generate plots) is simply a non-issue.
    – Alan Munn
    Aug 30, 2022 at 17:05
  • show the structure of the R data file and it should be possible to convert the data values.
    – user187802
    Aug 30, 2022 at 18:27
  • @AlanMunn I'm not a R user. But I use pgfplots quite often, for various types of graphs/animations, and I find it very useful to uncouple data generation and data visualisation. Now, if ggplot2 provides functionalities that overcome those of pgfplots (for instance), which is a situation I never faced in 2D, I understand. Out of curiosity, would you have an example of plot with ggplot2 that would be difficult with pgfplots?
    – anderstood
    Aug 31, 2022 at 12:07


You must log in to answer this question.

Browse other questions tagged .