我正在使用ggplot2(分别是qplot)来生成一个带有Sweave的报告.现在我需要一些帮助来调整绘图的大小.我使用以下Sweave代码来包含它.
\begin{figure}[htbp]
\begin{center}
<<fig=true,echo=false>>=
print(mygraph)
@
\caption{MyCaption}
\end{center}
\end{figure}
Run Code Online (Sandbox Code Playgroud)
如果我添加一个宽度参数(如下图所示)来绘制图表,但是没有真正按比例缩小.
<<fig=true,echo=false,width=3>>=
Run Code Online (Sandbox Code Playgroud)
如果我使用ggsave()代替,我可以使用scale参数并影响生成的.pdf文件的大小.有没有办法影响绘图的尺寸而不保存它(因为.pdf是由Sweave生成的)?我需要添加到我的qplot代码中吗?
mygraph=qplot(date,value,data=graph1,geom="line",colour=variable,xlab="",ylab="")
+ scale_y_continuous(limits = c(-0.3,0.3))
Run Code Online (Sandbox Code Playgroud)
Thx提前提出任何建议!
我正在制作R Sweave报告.我在sweave pdf输出中对ggplot维度有一些困难.我的代码:
\documentclass{report}
\begin{document}
demo demo demo demo demo demo demo demo demo demo demo demo
\begin{figure}[h]
\begin{center}
<<echo=FALSE, fig=TRUE>>=
require(ggplot2)
df <- data.frame(a= c(1:10), b = c (10:1))
ggplot(data = df, aes(a, b)) + geom_line()
@
\caption{caption}
\end{center}
\end{figure}
demo demo demo demo demo demo demo demo demo demo demo demo
\end{document}
Run Code Online (Sandbox Code Playgroud)
现在我想控制pdf输出中的绘图宽度和高度尺寸.实际上我想保持高度相同,但使宽度与文本宽度相同.
谢谢你的时间.
当我使用 时barplot,如果名称太大,我看不到条的名称。例如:
barplot(as.numeric(c(2, 4, 1, 6)), col = c("lightblue"), main="Barplot",
names.arg=c("This is bar 1...1", "This is bar 1...2",
"This is bar 1...3", "This is bar 1...4"),
xpd=TRUE, las=1, lwd=1, cex.names=0.5)
Run Code Online (Sandbox Code Playgroud)
当我使用时horiz=TRUE,我看不到左边的名字:
barplot(as.numeric(c(2, 4, 1, 6)), col = c("lightblue"), main="Barplot",
names.arg=c("This is \nbar 2...1", "This is bar 2...2",
"This is bar 2...3", "This is bar 2...4"),
xpd=TRUE, las=1, lwd=1, horiz=TRUE, space=1)
Run Code Online (Sandbox Code Playgroud)
在名称中使用换行符(例如“这是 \nbar 2...1”)或减小文本大小,例如cex.names=0.5“解决”问题,但我更愿意添加空格以使名称适合。
有没有能力改变包括情节在内的整个图形的宽度?