1

I have a nice coefplot that plotting an object that I calculated with feglm command. Now I want to save it as an pdf and jpeg object that I could export somewhere else. I would also like to tinker with the width and height.

Thank you,

YouLocalRUser
  • 309
  • 1
  • 9

2 Answers2

0

You use pdf(), plot it, then dev.off(). For example:

est = feols(Petal.Length ~ Petal.Width + Sepal.Length +
              Sepal.Width | Species, iris)

pdf("plot.pdf")
coefplot(est)
dev.off()
pbaylis
  • 1,529
  • 11
  • 19
0

To add to Patrick's answer, those are regular base-R graphs, so any regular export tool work.

FWIW the fplot's package contains dedicated tools to export graphs that may facilitate graph exportation.

The principle is the same:

library(fixest) ; library(fplot)

est = feols(Petal.Length ~ Petal.Width + Sepal.Length +
              Sepal.Width | Species, iris)

pdf_fit("plot.pdf")
coefplot(est)
fit.off()

Instead of pdf/dev.off, here it's fplot's equivalent pdf_fit/fit.off. What's the difference?

  • you give the desired point size of the text in your graph in your target document (typically US letter or A4)
  • you give the target width (or height) in your final document as a fraction of text size

You should end up with a graph for which the text is "garanteed" to have the specified point size in your final document. After exportation, the exported graph is also displayed in RStudio's viewer, so you can check directly if you like it or not.

See more detailed explanations in the dedicated vignette

Laurent Bergé
  • 1,292
  • 6
  • 8