# Cropping an image generated in R code

I would like to crop an image that is not inserted (which has been searched a lot), but an image that is generated in R code.

\documentclass{article}
\setlength{\parindent}{0pt}
\setcounter{secnumdepth}{0}
\usepackage[round,sort]{natbib}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfig}
\usepackage{verbatim}
\usepackage{amssymb,amsbsy,amsmath}
\usepackage{epsfig}
\usepackage[left=3cm,top=3cm,bottom=3.5cm,right=3cm]{geometry}
\usepackage{fancyhdr}
\numberwithin{equation}{section}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<label=plotName, include=FALSE>>=
someFunctionInR(someParameter)
@

\setkeys{Gin}{width=4in, height=4in}
\begin{figure}
\begin{center}
<<label=plotName,fig=TRUE,echo=FALSE>>=
<<plotName>>
@
\end{center}
\caption{Some caption.}
\label{fig:plotName}
\end{figure}


I tried to insert a statement as follows:

\includegraphics[clip=true,trim=0cm 1cm 0cm 1cm]


I did this in several locations, but for instance, immediately in the line after \begin{center}, I get an error ("Undefined control sequence").

Any suggestions would be greatly appreciated!

• You will have better success with trimming the figure inside the Sweave block using the R plot options commands. – R. Schumacher Feb 25 '15 at 1:19

The adjustbox package provides the adjustbox environment which you should be able to use for this purpose. Your setup should resemble:

% ... preamble content

% ... main document content

\begin{figure}[htb]
\centering