简体   繁体   English

秤整个 R plot

[英]Scale entire R plot

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.要解决Word PDF 导出对嵌入的 SVG 图形施加最小线宽的问题,我需要创建 R 图的缩放版本。 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:我想创建一个大小为 10 倍的 SVG:

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.同时,我不希望 plot 中的任何内容相对于彼此发生变化。 So plotAx10.svg scaled to 10% should be exactly the same as plotA.svg .所以plotAx10.svg缩放到 10% 应该与plotA.svg

I can achieve most of what I want with the cex and lwd graphics parameters, eg with par(cex=0.8*10, lwd=10) .我可以使用cexlwd图形参数实现大部分我想要的,例如使用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?如果不是,需要单独配置哪些功能?

AFAIK, there is no global scaling parameter. AFAIK,没有全局缩放参数。 cex and lwd are a good start, but you'll also need to modify a few other function calls. cexlwd是一个好的开始,但您还需要修改其他几个 function 调用。 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, eg对于 SVG 导出中的比例图,我将在变量中定义比例因子,例如

sc = 10

You'll then need to use it in svg and par :然后你需要在svgpar中使用它:

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 .每当您在图形 function 上显式设置lwdcex时,该值都需要乘以sc Also, the following commands don't take the settings from par , so you'll need to explicitly set the scaled values to them, eg with此外,以下命令不采用par的设置,因此您需要为它们明确设置缩放值,例如

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

The points function is an exception to this rule. points function 是该规则的一个例外。 If you have set the cex parameter to that function, eg如果您已将cex参数设置为该 function,例如

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 . points function 似乎在内部将参数值与值全局cex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM