为什么导出时R会重新调整绘图中所有内容的大小,而不调整文本的大小? [英] Why does R re-size everything in the plot but not the text when exported?

查看:519
本文介绍了为什么导出时R会重新调整绘图中所有内容的大小,而不调整文本的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试用RStudio和pdf()导出R绘图时,我都会发现所有元素都相应地调整了大小,但没有调整文本的大小.这甚至可能导致标题被切断.

Whenever I try to export R plot, either with RStudio with with pdf(), I find that all the elements are re-sized accordingly but not the text. This can lead to titles being cut off even.

尝试在Rstudio中调整此图的大小(或在基本R中使用pdf("plot.pdf", width, height)):

Try resize this plot in Rstudio (or use pdf("plot.pdf", width, height) in base R):

ggplot(data=data.frame(x=rnorm(100), y=rnorm(100)), aes(x, y)) +
  geom_point() +
  geom_text(aes(label=rep("a", 100))) +
  labs(y="Title that is very loooooooooooooooooooooooooooooooooooooooong")

width x height5 x 5时,文本过大且标题被截断.但是作为10 x 10,一切都适合.

When width x height is 5 x 5, the text is oversized and the title is cut-off. But as 10 x 10, everything fits in.

因此,无论我为图的大小指定什么,文本似乎都保持恒定的大小".这是对R如何导出图形的正确理解吗?

So it seems like the text remains at a constant "size" no matter what I specify for the size of the plot. Is this a correct understanding of how R export graphics?

如果是这种情况,通常如何确保导出的图形中的文本适合?

If that's the case, what do you typically do to make sure that the text in the exported graphics fit in?

推荐答案

我终于看到了此行为背后的直观性.当我发布问题时,我希望R在调整图形大小时能够调整图形中所有元素的大小.

I finally see the intuitiveness behind this behavior. When I posted the question, I expect R to resize all the elements inside the graph when I resize the graph.

但是,实际上,所有元素的大小都是固定的,包括文本,线条,刻度线等,并且重新调整图形的大小仅会更改图形的大小,同时保持元素的相对位置.

However, in fact, the size of ALL elements are fixed, including text, line, tick mark, etc., and re-sizing the graph only changes the size of the graph while maintaining the relative position of the elements.

要查看此内容,请运行pdf("small.pdf",5,5); plot(1,1); dev.off() and pdf("large.pdf",10,10); plot(1,1); dev.off().然后,如果显示两个图形,请缩放以使屏幕上的物理尺寸为<​​c6>和10x10,两个图之间的元素尺寸应该相同.

To see this, run pdf("small.pdf",5,5); plot(1,1); dev.off() and pdf("large.pdf",10,10); plot(1,1); dev.off(). Then, if you display the two graphs, zoom so that the physical size on screen is 5x5 and 10x10, the element sizes should be the same between the two plots.

因此最佳实践可能是(请分享您的实践):

So the best practice is probably (please share your practice):

  1. 在绘制时,指定相对彼此有意义的元素大小,
  2. 导出时,选择适合所有情况的打印尺寸
  3. 使用\includegraphics[width=\textwidth, height=\textheight,keepaspectratio]
  4. 导入乳胶
  1. when plotting specify elements' sizes that make sense relative to one another,
  2. when exporting, choose a plot size that everything fits in,
  3. import into latex using \includegraphics[width=\textwidth, height=\textheight,keepaspectratio]

这篇关于为什么导出时R会重新调整绘图中所有内容的大小,而不调整文本的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆