2015-11-03 74 views
0

我正在使用knitr,ggplot。我想要一个这样的情节: Plot wider 显示更好。但我仍然得到这样的: narrow plotggplot2中的变化率

\begin{landscape} 
<< mygrah2>>= 
require(ggplot2) 
ggplot(T2,aes(x=age,y=value,fill=Position)) 
+geom_boxplot()+ggtitle("Distribuition of frequencies per age in 3 
collected positions.\n N=1000,K=10,T=2")+theme(legend.position="bottom") 
@ 
\end{landscape} 

我已经尽量选择out.widthfig.width但不工作。

编辑:

我确定我正在使用knitr。我在下面做了一个例子。作为@Thierry,令人难过的解决方案是一起使用fig.height和fig.width。非常感谢。

\documentclass[letterpaper,12pt]{article} 

\usepackage{graphicx} 
\usepackage[utf8]{inputenc} 
\usepackage[brazil]{babel} 
\usepackage{color} 

\usepackage{placeins} 
\usepackage{graphicx} 

\usepackage{booktabs} 

\usepackage{lscape} 
\usepackage{fullpage} 
\usepackage{pdflscape} 


\begin{document} 

<<readdata>>= 
data(mtcars) 
mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5), 
    labels=c("3gears","4gears","5gears")) 
mtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8), 
    labels=c("4cyl","6cyl","8cyl")) 

require(ggplot2) 
@ 

\begin{landscape} 
<<migraph>>= 
#normal plot 
ggplot(mtcars,aes(x=gear,y=mpg,fill=gear))+geom_boxplot() 
@ 


<<migraph2,fig.width=10>>= 
# weird 
ggplot(mtcars,aes(x=gear,y=mpg,fill=gear))+geom_boxplot() 
@ 

<<migraph3,fig.height=2,fig.width=10>>= 
# It is what I looking for 
ggplot(mtcars,aes(x=gear,y=mpg,fill=gear))+geom_boxplot() 
@ 


<<migraph4,out.height="2in",out.width="10in">>= 
# weird 
ggplot(mtcars,aes(x=gear,y=mpg,fill=gear))+geom_boxplot() 
@ 

\end{landscape} 

\end{document} 
+2

设置fig.width和fit.height应该工作。如果没有,然后发布一个可重复的例子 – Thierry

+0

[如何使一个伟大的R可重现的例子?](http://stackoverflow.com/questions/5963269) – zx8754

+0

你确定你正在使用knitr吗?您可以检查您是否使用Sweave - >工具 - >全局选项 - > Sewave - >使用 - 编织Rnw文件 - >检查您是否有knitr或Sweave?如果你想使用knitr块选项,你应该换成knitr –

回答

1

fig.widthout.width的行为是不同的。 fig.width控制实际数字的大小,比如5英寸。 out.width选项控制图形在文档中的显示方式。因此,如果您有fig.width = 5out.width = 0.5\\textwidth,则将创建一个5英寸宽的数字,并且在LaTeX中,该图形将通过\includegraphics[width = 0.5\textwidth]包含在内。请注意,在定义out.width的值时需要转义反斜杠。

默认情况下,该卡盘的选项有:

  • fig.width = 7
  • fig.height = 7
  • out.width = NULL
  • out.height = NULL

out.*选项的缺省值被输出类型设置。请参阅chunk options的文档。

migraph是7×7数字与\includegraphics[width=\maxwidth]其中\maxwidth定义here

migraph2是10x7数字具有相同的默认输出宽度。

migraph3是具有标准输出宽度的2x10英寸数字。

migraph4强制一个7x7英寸的数字到一个10x2英寸的框架,是的,这看起来很奇怪。