Eti*_*rie 22 pdf plot r ggplot2
虽然发送到PDF的R图可以在插图或页面布局软件中随意重新调整,但科学期刊通常坚持提供的图表具有特定的尺寸.
所有绘图元素的大小可以直接在R中在给定的PDF大小内缩放吗?
require(ggplot2)
p <- qplot(data=iris,
x=Petal.Width,
y=Petal.Length,
colour=Species)
pdf("./test_plot_default.pdf")
print(p)
graphics.off()
Run Code Online (Sandbox Code Playgroud)
生成适当的绘图元素缩放

但是,更改PDF大小元素不会导致绘图元素缩放.对于较小的PDF,绘图元素与绘图空间相比过度放大.
pdf("./test_plot_dimentionsions required by journal.pdf", width=3, height=3)
print(p)
graphics.off()
Run Code Online (Sandbox Code Playgroud)

使用@Rosen Matev建议:
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()
Run Code Online (Sandbox Code Playgroud)

Pet*_*usu 11
考虑在 pdf() 函数中使用width、height和pointsize。
如果您喜欢坚持使用 pdf() 而不是使用 sweave 等其他方式,那么您最好使用带有更多参数的 pdf 函数,如下所示(我没有安装 ggplot2,因此提供了类似的情况)。
# making scaled plot in pdf
# using paper=a4 just to see the efect
for (sc in c(0.5,0.75,1)) {
pdf(width=7*sc,height=7*sc,pointsize=12*sc,file=paste("scale",sc,".pdf",sep=""),paper="a4")
plot(sin((1:314)/100),main=paste("PDF sc",sc))
dev.off()
}
Run Code Online (Sandbox Code Playgroud)
它非常有用,但在某种程度上有效。一旦比例太小,pdf 将开始强制执行线宽、字体大小等。
请参阅示例创建的scale*.pdf 中的结果。
对于 ggplot2 ...
sc <- c(0.5,0.75,1)
fi <- c("pic1.pdf","pic2.pdf","pic3.pdf")
require(ggplot2)
p <- qplot(data=iris,
x=Petal.Width,
y=Petal.Length,
colour=Species)
for (i in 1:3) {
pdf(width=7*sc[i],height=7*sc[i],pointsize=12*sc[i],file=fi[i])
print(p)
dev.off()
}
Run Code Online (Sandbox Code Playgroud)
用于测试文件在一个文档中的外观的 Latex 代码:
\documentclass[a4paper,11pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphics}
\begin{document}
\begin{figure}
\includegraphics{pic1.pdf}
\end{figure}
\begin{figure}
\includegraphics{pic2.pdf}
\end{figure}
\begin{figure}
\includegraphics{pic3.pdf}
\end{figure}
\end{document}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,你可以用scale=inggsave(...)
require(ggplot2)
p <- qplot(data=iris, x=Petal.Width, y=Petal.Length, colour=Species)
ggsave("test.1.pdf",p)
ggsave("test.2.pdf",p, width=3, height=3, units="in", scale=3)
Run Code Online (Sandbox Code Playgroud)
尝试使用scale参数,看看你得到了什么......
期刊坚持要求具有特定的情节尺寸以避免缩放.如果制作,它可以使字体大小太小(或大)并且与图标题字体大小不一致.这就是为什么设计中的绘图元素(文本,点大小等)具有相同的绝对大小,而与pdf大小无关.
您可以更改默认字体大小和磅值,例如:
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)
Run Code Online (Sandbox Code Playgroud)
默认值也可以全局更改:
update_geom_defaults("point", list(size=1.5))
theme_set(theme_grey(base_size=10))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26795 次 |
| 最近记录: |