| 1 |
#LyX 2.0 created this file. For more info see http://www.lyx.org/ |
| 2 |
\lyxformat 413 |
| 3 |
\begin_document |
| 4 |
\begin_header |
| 5 |
\textclass article |
| 6 |
\begin_preamble |
| 7 |
\renewcommand{\textfraction}{0.05} |
| 8 |
\renewcommand{\topfraction}{0.8} |
| 9 |
\renewcommand{\bottomfraction}{0.8} |
| 10 |
\renewcommand{\floatpagefraction}{0.75} |
| 11 |
\end_preamble |
| 12 |
\use_default_options true |
| 13 |
\begin_modules |
| 14 |
knitr |
| 15 |
\end_modules |
| 16 |
\maintain_unincluded_children false |
| 17 |
\language english |
| 18 |
\language_package default |
| 19 |
\inputencoding auto |
| 20 |
\fontencoding global |
| 21 |
\font_roman default |
| 22 |
\font_sans default |
| 23 |
\font_typewriter default |
| 24 |
\font_default_family default |
| 25 |
\use_non_tex_fonts false |
| 26 |
\font_sc false |
| 27 |
\font_osf false |
| 28 |
\font_sf_scale 100 |
| 29 |
\font_tt_scale 100 |
| 30 |
|
| 31 |
\graphics default |
| 32 |
\default_output_format default |
| 33 |
\output_sync 0 |
| 34 |
\bibtex_command default |
| 35 |
\index_command default |
| 36 |
\paperfontsize default |
| 37 |
\spacing single |
| 38 |
\use_hyperref false |
| 39 |
\papersize default |
| 40 |
\use_geometry false |
| 41 |
\use_amsmath 1 |
| 42 |
\use_esint 1 |
| 43 |
\use_mhchem 1 |
| 44 |
\use_mathdots 1 |
| 45 |
\cite_engine basic |
| 46 |
\use_bibtopic false |
| 47 |
\use_indices false |
| 48 |
\paperorientation portrait |
| 49 |
\suppress_date false |
| 50 |
\use_refstyle 1 |
| 51 |
\index Index |
| 52 |
\shortcut idx |
| 53 |
\color #008000 |
| 54 |
\end_index |
| 55 |
\secnumdepth 3 |
| 56 |
\tocdepth 3 |
| 57 |
\paragraph_separation indent |
| 58 |
\paragraph_indentation default |
| 59 |
\quotes_language english |
| 60 |
\papercolumns 1 |
| 61 |
\papersides 1 |
| 62 |
\paperpagestyle default |
| 63 |
\tracking_changes false |
| 64 |
\output_changes false |
| 65 |
\html_math_output 0 |
| 66 |
\html_css_as_file 0 |
| 67 |
\html_be_strict false |
| 68 |
\end_header |
| 69 |
|
| 70 |
\begin_body |
| 71 |
|
| 72 |
\begin_layout Standard |
| 73 |
\begin_inset ERT |
| 74 |
status open |
| 75 |
|
| 76 |
\begin_layout Plain Layout |
| 77 |
|
| 78 |
<<setup, include=FALSE>>= |
| 79 |
\end_layout |
| 80 |
|
| 81 |
\begin_layout Plain Layout |
| 82 |
|
| 83 |
library(knitr) |
| 84 |
\end_layout |
| 85 |
|
| 86 |
\begin_layout Plain Layout |
| 87 |
|
| 88 |
opts_chunk$set(fig.path='figure/subfloats-') |
| 89 |
\end_layout |
| 90 |
|
| 91 |
\begin_layout Plain Layout |
| 92 |
|
| 93 |
@ |
| 94 |
\end_layout |
| 95 |
|
| 96 |
\end_inset |
| 97 |
|
| 98 |
|
| 99 |
\end_layout |
| 100 |
|
| 101 |
\begin_layout Title |
| 102 |
Using subfloats in LyX with knitr |
| 103 |
\end_layout |
| 104 |
|
| 105 |
\begin_layout Author |
| 106 |
Yihui Xie |
| 107 |
\end_layout |
| 108 |
|
| 109 |
\begin_layout Standard |
| 110 |
If you insert a float figure inside a float figure in LyX, you will get |
| 111 |
subfloats. |
| 112 |
To make sure the two subfloats can stand side by side, you have to: |
| 113 |
\end_layout |
| 114 |
|
| 115 |
\begin_layout Enumerate |
| 116 |
remove new lines between the two subfloat environments in LyX (if you are |
| 117 |
not sure if there are blank lines between them, check the LaTeX source); |
| 118 |
\end_layout |
| 119 |
|
| 120 |
\begin_layout Enumerate |
| 121 |
use the chunk option |
| 122 |
\family typewriter |
| 123 |
echo=FALSE |
| 124 |
\family default |
| 125 |
to hide the R source code in the output; |
| 126 |
\end_layout |
| 127 |
|
| 128 |
\begin_layout Enumerate |
| 129 |
set |
| 130 |
\family typewriter |
| 131 |
out.width |
| 132 |
\family default |
| 133 |
to be less than half of the linewidth if you do not want the sub figures |
| 134 |
to exceed the page margin; |
| 135 |
\end_layout |
| 136 |
|
| 137 |
\begin_layout Enumerate |
| 138 |
most importantly, leave a blank line in the beginning of the subfloat environmen |
| 139 |
t, so that |
| 140 |
\family typewriter |
| 141 |
<<>>= |
| 142 |
\family default |
| 143 |
starts in a new line and |
| 144 |
\series bold |
| 145 |
knitr |
| 146 |
\series default |
| 147 |
can recognize it; |
| 148 |
\end_layout |
| 149 |
|
| 150 |
\begin_layout Standard |
| 151 |
Figure |
| 152 |
\begin_inset CommandInset ref |
| 153 |
LatexCommand ref |
| 154 |
reference "fig:knitr-subfloat" |
| 155 |
|
| 156 |
\end_inset |
| 157 |
|
| 158 |
is an example. |
| 159 |
\end_layout |
| 160 |
|
| 161 |
\begin_layout Standard |
| 162 |
This document was compiled with |
| 163 |
\series bold |
| 164 |
knitr |
| 165 |
\series default |
| 166 |
|
| 167 |
\begin_inset ERT |
| 168 |
status open |
| 169 |
|
| 170 |
\begin_layout Plain Layout |
| 171 |
|
| 172 |
|
| 173 |
\backslash |
| 174 |
Sexpr{packageVersion('knitr')} |
| 175 |
\end_layout |
| 176 |
|
| 177 |
\end_inset |
| 178 |
|
| 179 |
. |
| 180 |
Rnw source at |
| 181 |
\begin_inset Flex URL |
| 182 |
status collapsed |
| 183 |
|
| 184 |
\begin_layout Plain Layout |
| 185 |
|
| 186 |
https://github.com/yihui/knitr/blob/master/inst/examples/knitr-subfloats.Rnw |
| 187 |
\end_layout |
| 188 |
|
| 189 |
\end_inset |
| 190 |
|
| 191 |
. |
| 192 |
\end_layout |
| 193 |
|
| 194 |
\begin_layout Standard |
| 195 |
\begin_inset Float figure |
| 196 |
wide false |
| 197 |
sideways false |
| 198 |
status open |
| 199 |
|
| 200 |
\begin_layout Plain Layout |
| 201 |
\begin_inset Float figure |
| 202 |
wide false |
| 203 |
sideways false |
| 204 |
status open |
| 205 |
|
| 206 |
\begin_layout Plain Layout |
| 207 |
\begin_inset ERT |
| 208 |
status open |
| 209 |
|
| 210 |
\begin_layout Plain Layout |
| 211 |
|
| 212 |
\end_layout |
| 213 |
|
| 214 |
\begin_layout Plain Layout |
| 215 |
|
| 216 |
<<test-subfloat, echo=FALSE, out.width='.45 |
| 217 |
\backslash |
| 218 |
|
| 219 |
\backslash |
| 220 |
linewidth'>>= |
| 221 |
\end_layout |
| 222 |
|
| 223 |
\begin_layout Plain Layout |
| 224 |
|
| 225 |
plot(1) |
| 226 |
\end_layout |
| 227 |
|
| 228 |
\begin_layout Plain Layout |
| 229 |
|
| 230 |
@ |
| 231 |
\end_layout |
| 232 |
|
| 233 |
\end_inset |
| 234 |
|
| 235 |
|
| 236 |
\end_layout |
| 237 |
|
| 238 |
\begin_layout Plain Layout |
| 239 |
\begin_inset Caption |
| 240 |
|
| 241 |
\begin_layout Plain Layout |
| 242 |
this is a subfloat |
| 243 |
\end_layout |
| 244 |
|
| 245 |
\end_inset |
| 246 |
|
| 247 |
|
| 248 |
\end_layout |
| 249 |
|
| 250 |
\end_inset |
| 251 |
|
| 252 |
|
| 253 |
\begin_inset Float figure |
| 254 |
wide false |
| 255 |
sideways false |
| 256 |
status open |
| 257 |
|
| 258 |
\begin_layout Plain Layout |
| 259 |
\begin_inset ERT |
| 260 |
status open |
| 261 |
|
| 262 |
\begin_layout Plain Layout |
| 263 |
|
| 264 |
\end_layout |
| 265 |
|
| 266 |
\begin_layout Plain Layout |
| 267 |
|
| 268 |
<<test-another, echo=FALSE, out.width='.45 |
| 269 |
\backslash |
| 270 |
|
| 271 |
\backslash |
| 272 |
linewidth'>>= |
| 273 |
\end_layout |
| 274 |
|
| 275 |
\begin_layout Plain Layout |
| 276 |
|
| 277 |
plot(rnorm(100)) |
| 278 |
\end_layout |
| 279 |
|
| 280 |
\begin_layout Plain Layout |
| 281 |
|
| 282 |
@ |
| 283 |
\end_layout |
| 284 |
|
| 285 |
\end_inset |
| 286 |
|
| 287 |
|
| 288 |
\end_layout |
| 289 |
|
| 290 |
\begin_layout Plain Layout |
| 291 |
\begin_inset Caption |
| 292 |
|
| 293 |
\begin_layout Plain Layout |
| 294 |
another float |
| 295 |
\end_layout |
| 296 |
|
| 297 |
\end_inset |
| 298 |
|
| 299 |
|
| 300 |
\end_layout |
| 301 |
|
| 302 |
\end_inset |
| 303 |
|
| 304 |
|
| 305 |
\end_layout |
| 306 |
|
| 307 |
\begin_layout Plain Layout |
| 308 |
\begin_inset Caption |
| 309 |
|
| 310 |
\begin_layout Plain Layout |
| 311 |
one figure with 2 sub figures |
| 312 |
\begin_inset CommandInset label |
| 313 |
LatexCommand label |
| 314 |
name "fig:knitr-subfloat" |
| 315 |
|
| 316 |
\end_inset |
| 317 |
|
| 318 |
|
| 319 |
\end_layout |
| 320 |
|
| 321 |
\end_inset |
| 322 |
|
| 323 |
|
| 324 |
\end_layout |
| 325 |
|
| 326 |
\end_inset |
| 327 |
|
| 328 |
|
| 329 |
\end_layout |
| 330 |
|
| 331 |
\end_body |
| 332 |
\end_document |