friendly / VCDR

Visualizing categorical data with R
0 stars 0 forks source link

General: use of op<-par() ... par(op), pdfcrop #22

Closed friendly closed 9 years ago

friendly commented 9 years ago

I like to have graphs with tight bounding boxes, but in quite a few places, the graphs have excessively large figure margins, so I've used code like

op <- par(mar=c(4,4,1,1)+.1)
plot(...)
abline()
par(op)

I'd rather not show these setting lines in the text, and so I've sometimes used the chunk option echo

<<echo=2:3>>=
op <- par(mar=c(4,4,1,1)+.1)
plot(...)
abiline()
par(op)
@

If you see such lines appearing in the text, try to fix them. For graphs that don't obey par() settings, there is also the crop chunk option that invokes pdfcrop. However, that's expensive, in that it adds considerably to knit time. Probably should use cache=TRUE here, or just cheat and use includegraphics on the cropped image file.

philchalmers commented 9 years ago

You shouldn't need to use the last line, par(op), because knitr resets the par argument automatically after each chunk is complete. Also, echo accepts negation indexing, so you can remove lines with the - operator. So this would be a more robust approach:

<<echo=-1>>=
par(mar=c(4,4,1,1)+.1)
plot(...)
abiline()
friendly commented 9 years ago

Fixed many of these, but there are still some remaining usages of par(op) in Ch6, Ch7, Ch10, Ch11