R在设置宽度和高度的PDF中绘制标尺图元素 [英] R Scale plot elements within PDF of set width and height

查看:999
本文介绍了R在设置宽度和高度的PDF中绘制标尺图元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然发送到PDF的R图可以在插图或页面布局软件中随意重新调整,但科学期刊常常坚持提供的图具有特定的尺寸。 b
$ b

所有绘图元素的大小是否可以在R中直接缩放给定的PDF大小?

  require(ggplot2)

p < - qplot(data = iris,
x = Petal.Width,
y = Petal.Length,
color =种类)

pdf( ./test_plot_default.pdf)
print(p)
graphics.off()

产生足够的绘图元素缩放比例



但是,更改PDF大小元素不会导致绘图元素缩放。对于较小的PDF,绘图元素与绘图空间相比过度放大。

  pdf(./ test_plot_dimentionsions journal of journal。 pdf),width = 3,height = 3)
print(p)
graphics.off()


<使用@Rosen Matev建议:

$ $ p $ update_geom_default(point,list(size = 1))
theme_set (theme_grey(base_size = 6))
pdf(./ test_plot_dimentionsions required for journal.pdf,width = 3,height = 3)
print(p)
graphics.off()

解决方案

期刊坚持有特定的绘图尺寸以避免缩放。如果制作,它可能会使字体大小太小(或较大),并与数字字幕字体大小不一致。这就是为什么设计中的情节元素(文字,磅值等)具有相同的绝对尺寸,而与pdf尺寸无关。



您可以更改默认字体大小和点的大小,例如:

  p < -  ggplot(iris,aes(x = Petal.Width,y = Petal.Length,color = Species))+ 
geom_point(size = 1.5)+#default是2
theme_grey(base_size = 10)#default是12
ggsave(test.1。 pdf,p)

默认值也可以全局更改:

  update_geom_defaults(point,list(size = 1.5))
theme_set(theme_grey(base_size = 10))


Though R plots sent to a PDF can be rescaled at will in an illustration or page layout software, scientific journals often insist that the plots provided have specific dimensions.

Can the size of all plotting elements be scaled within a given PDF size directly in R?

require(ggplot2)

p <- qplot(data=iris,
           x=Petal.Width,
           y=Petal.Length,
           colour=Species)

pdf("./test_plot_default.pdf")
print(p)
graphics.off()

Produces adequate scaling of plot elements

However, changing PDF size elements does not cause the plot elements to scale. With smaller PDFs, the plotting elements are overly enlarged compared to the plotting space.

pdf("./test_plot_dimentionsions required by journal.pdf", width=3, height=3)
print(p)
graphics.off()

Using @Rosen Matev suggestion:

update_geom_default("point", list(size=1))
theme_set(theme_grey(base_size=6))
pdf("./test_plot_dimentionsions required by journal.pdf", width=3, height=3)
print(p)
graphics.off()

解决方案

Journals insist on having specific plot dimensions in order to avoid scaling. If made, it can render the font size too small (or large) and inconsistent with the figure caption font size. That is why the plot elements (text, point size, etc.) by design have the same absolute size regardless of pdf size.

You can change the default font size and point size, for example, with:

p <- ggplot(iris, aes(x=Petal.Width, y=Petal.Length, colour=Species)) +
  geom_point(size=1.5) +  # default is 2
  theme_grey(base_size=10)  # default is 12
ggsave("test.1.pdf", p)

The defaults can be changed globally, too:

update_geom_defaults("point", list(size=1.5))
theme_set(theme_grey(base_size=10))

这篇关于R在设置宽度和高度的PDF中绘制标尺图元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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