0

I am using knitr, ggplot. I want a plot like this: Plot wider to be shown better. But I still get something like this: narrow plot

\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}

I already try options out.width, fig.width but not working.

Edit:

I am sure that I'm using knitr. I did an example below. As @Thierry sad the solution is use a fig.height AND fig.width together. Thanks very much.

\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}
989
  • 12,579
  • 5
  • 31
  • 53
Tomate
  • 195
  • 1
  • 5
  • 2
    setting fig.width and fit.height should work. If not, then post a reproducible example – Thierry Nov 03 '15 at 08:48
  • [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269) – zx8754 Nov 03 '15 at 09:25
  • Are you sure your are using knitr? You can check whether you are not using Sweave -> Tools -> Global Options -> Sewave -> Weave Rnw files using -> check whether you have there knitr or Sweave? You should change to knitr if your want to use knitr chunks options – Marcin Nov 03 '15 at 10:26

1 Answers1

1

The behavior of fig.width and out.width are different. fig.width controls the size of the actual figure, say 5 inches. The out.width option controls how the graphic is displayed in the document. As such, if you have fig.width = 5 and out.width = 0.5\\textwidth then a figure that is five inches wide is created, and in LaTeX, the graphic is included via \includegraphics[width = 0.5\textwidth] Note that the backslash needs to be escaped when defining the value for out.width.

By default, the chuck options are:

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

The out.* options defaults are set by output type. See the documentation for chunk options.

Your migraph is a 7x7 figure with \includegraphics[width=\maxwidth] where \maxwidth is defined here

migraph2 is a 10x7 figure with the same default output width.

migraph3 is a 2x10 inch figure with standard output width.

migraph4 forces a 7x7 inch figure into a 10x2 inch frame, yeah, that's going to look weird.

Peter
  • 7,460
  • 2
  • 47
  • 68