0

To work around the problem that the Word PDF export imposes a minimum line width on embedded SVG graphics, I need to create scaled versions of my R plots. For example, instead of

svg(file="plotA.svg", width=5.9, height=3)

I'd want to create an SVG with 10 times the size:

svg(file="plotAx10.svg", width=59, height=30)

At the same time, I don't want anything in the plot to change relative to each other. So plotAx10.svg scaled to 10% should be exactly the same as plotA.svg.

I can achieve most of what I want with the cex and lwd graphics parameters, e.g. with par(cex=0.8*10, lwd=10). However there are some functions, which don't seem to take them into account. Is this the right approach? Or did I miss some other global scale parameter? If not, which functions need to be configured separately?

oberlies
  • 11,503
  • 4
  • 63
  • 110

1 Answers1

0

AFAIK, there is no global scaling parameter. cex and lwd are a good start, but you'll also need to modify a few other function calls. If you do so, however, you'll get a (sub-)pixel perfect scaled up version of your plots.

For scaling plots in SVG export, I'd define the scale factor in a variable, e.g.

sc = 10

You'll then need to use it in svg and par:

svg(file="...", width=sc*5.9, height=sc*3)
par(cex=sc*0.8, lwd=sc)

Whenever you set lwd or cex on a graphics function explicitly, that value needs to be multiplied by sc. Also, the following commands don't take the settings from par, so you'll need to explicitly set the scaled values to them, e.g. with

axis(..., lwd=par()[["lwd"]])
mtext(..., cex=par()[["cex"]])

The points function is an exception to this rule. If you have set the cex parameter to that function, e.g.

points(..., cex=0.72)

this call needs to stay as it is. The points function seems to internally multiply the parameter value with the value global cex.

oberlies
  • 11,503
  • 4
  • 63
  • 110