Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non default plot size messes with "legend" #258

Closed
knokknok opened this issue May 29, 2012 · 5 comments
Closed

Non default plot size messes with "legend" #258

knokknok opened this issue May 29, 2012 · 5 comments
Labels
bug Bugs
Milestone

Comments

@knokknok
Copy link
Contributor

I would expect the plots produced by the 2 samples below to be identical but they are not:

library(knitr)
knit_patterns$set(all_patterns$rnw)
opts_knit$set(out.format = 'latex')
render_latex()
knit(output = 'legend.tex', text = '
<<test, fig.width=12, fig.height=12>>=
x <- 0:64/64
matplot(x, outer(x, 1:7, function(x, k) sin(k * pi * x)), type = "o", col = 1:7, ylim = c(-1, 1.5), pch = "*")
legend("topleft", legend=paste("sin(", 1:7, "pi * x)"), col=1:7, lty=1:7, pch = "*", cex = 0.8)
@
')
pdf(width=12, height=12)
x <- 0:64/64
matplot(x, outer(x, 1:7, function(x, k) sin(k * pi * x)), type = "o", col = 1:7, ylim = c(-1, 1.5), pch = "*")
legend("topleft", legend=paste("sin(", 1:7, "pi * x)"), col=1:7, lty=1:7, pch = "*", cex = 0.8)
dev.off()

Notice that the legend spacing is incorrect (the result from knitr looks like what happens when you manually resize your device after plotting).

@yihui yihui closed this as completed in d9be63b May 29, 2012
yihui added a commit that referenced this issue May 29, 2012
@yihui
Copy link
Owner

yihui commented May 29, 2012

should be fixed now; you must be using an interactive R session, which is not good unless you have special reasons; normally you should call knitr in a non-interactive R session via R -e 'library(knitr);...' or Rscript -e ...

@knokknok
Copy link
Contributor Author

It is fixed, thanks!

I do use knitr interactively because I like being able to play with my objects and try things out before actually putting code in my Rnw.

Why is that bad?

@yihui
Copy link
Owner

yihui commented May 29, 2012

because finally you will have to run it non-interactively

when you run it interactively, the objects are generated in the global environment, and you may screw up some randomly without noticing it (e.g. you created a function in the console but forgot to do it in the source document)

if you want to do exploratory work, you can use RStudio to run code chunks; it is pretty convenient. When it comes to compile the whole document, just hit the button to compile it in a separate R session to guarantee everything works fine

@knokknok
Copy link
Contributor Author

Ok, thanks. I'm pretty entrenched in emacs+terminal though ;-)

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

2 participants