Creating a tikz image with two charts in a row

I had a question about creating two charts in a row, using R with a tikz package device to send tikz to latex. I want to do this by building 2 graphs in a row. The first thing I did was create plots surrounded by par(mfrow=c(1,2)) . But this does not work, because the plots are like vertical rectangles when printing with latex. I want two photos in a row to be quadratic. So what I did next, I created a layout:

 Layout<- matrix(c(1, 2), nrow = 1, ncol=2, byrow = TRUE) nf <- layout(mat = Layout, widths = c(1,1),heights = c(1,1), respect = TRUE) layout.show(nf) 

and built two graphs. The result is quadratic (this is good), but when I add a signature to two graphs (in latex), it is far from the graph. What should I do? Any thousands are appreciated!

+6
source share
2 answers

As Greg said, you need to adjust the width and height of the plot canvas if you want square sections, but don't want R to fill large border spaces.

The following is a minimal example of using Sweave:

 \documentclass{article} \usepackage{Sweave} \usepackage{tikz} <<echo=FALSE,results=hide>>= require(tikzDevice) @ \begin{document} \begin{figure} <<echo=FALSE,results=hide>>= # Standard LaTeX article class has a \textwidth of ~4.5in # Therefore, divide by 2 to get the right height. tikz('layout-ex.tex', width = 4.5, height = 2.25) Layout<- matrix(c(1, 2), nrow = 1, ncol=2, byrow = TRUE) nf <- layout(mat = Layout, widths = c(1,1),heights = c(1,1), respect = TRUE) layout.show(nf) dev.off() @ \centering \input{layout-ex} \label{fig:layout-ex} \caption{A layout with two sub-figures} \end{figure} \end{document} 

The resulting figure is as follows:

Example of using Layout

+2
source

You have set value = TRUE, so this means that your graphics inside the device occupy half the height (if the default values โ€‹โ€‹on the tikz device are used), and the rest of the height is filled with spaces. When you add a title, it moves away from the stories in this space. When you open the tikz device, set the height and width so that the height is close to half the width, and in the end you should get much less spaces, and the signature will be closer to the graphs.

+6
source

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


All Articles