How to use ggplot2 graphics inside a mini disk with sweave?

Here is my code, which should be displayed on the chart next to each other, but cannot do this. In fact, part of the sweave is not interpreted.

\begin{figure}[h]
\begin{center} 
\begin{minipage}[t]{.485\linewidth} % 
 <<fig=true,echo=false>>=
 print(graph2)
 @
 \newline{\color{red}{\caption{\label{idx}Graph one}}}    
 \end{minipage}
 \hspace{.02\linewidth}
  \begin{minipage}[t]{.485\linewidth}% 
  <<fig=true,echo=false>>=
 print(graph2)
 @
 \newline{\color{red}{ \caption{\label{pb}Graph two}}}
 \end{minipage}

 \end{center}
 \end{figure}

graph1, graph2 is any graph created by qplot. Both graphs work great outside the mini-disc. I know that this topic was around, but for some reason I could not get the solutions received for others, such as one .

Plus, I have a small question: what argument prevented Sweave from generating both .eps and .pdf? The manual states that it is the default. However, I am sure that I just use pdflatex and therefore do not need .eps.

+3
2

, , . minipage, , subfigure. Subfigure Sweave. !

, . , -:)

+3

\hspace \hfill . ggplot. minipage xtable .

\documentclass{article}
\usepackage{color}
\begin{document}

\begin{figure}[h]
\begin{center} 

\begin{minipage}[t]{.49\linewidth} % 
<<fig=true,echo=false>>=
require(ggplot2)

df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
                 y = rnorm(30))
library(plyr)
ds <- ddply(df, .(gp), summarise, mean = mean(y), sd = sd(y))

ggplot(df, aes(x = gp, y = y)) +
   geom_point() +
   geom_point(data = ds, aes(y = mean),colour = 'red', size = 3)

@
\newline{\color{red}{\caption{\label{idx}Graph one}}}    
\end{minipage}
\hfill
\begin{minipage}[t]{.49\linewidth}
<<fig=true,echo=false>>=
ggplot() +
  geom_point(data = df, aes(x = gp, y = y)) +
  geom_point(data = ds, aes(x = gp, y = mean),
                        colour = 'red', size = 3) +
  geom_errorbar(data = ds, aes(x = gp, y = mean,
                    ymin = mean - sd, ymax = mean + sd),
                    colour = 'red', width = 0.4)
@
\newline{\color{red}{ \caption{\label{pb}Graph two}}}
\end{minipage}

\end{center}
\end{figure}

\end{document}

enter image description here

+2

Source: https://habr.com/ru/post/1757316/


All Articles