knitr

Scaling plotly figures in knitr Latex document

喜你入骨 提交于 2019-12-05 13:58:16
I'm trying to include a plotly chart into a Latex document with knitr. Since knitr includes the webshot package this works well. But if I want to resize my figure for the latex output, the figure environment gets bigger but the plotly chart is not scalled to the manually set figure width and height. Specifing the webshot options like recommend here , did not work neither. Scaling a ggplot chart works well, but how can I get the same results for the plotly chart? \documentclass{article} \usepackage{cleveref} <<setup, echo=FALSE, message = FALSE, warning = FALSE>>= library(ggplot2) library

R code in LaTeX in YAML before_body include

僤鯓⒐⒋嵵緔 提交于 2019-12-05 13:57:15
I have a LaTeX section that I put at the top of my knitr generated PDF document. I achieved this by using the YAML options output: pdf_document: includes: before_body: file.tex file.tex contains code like this \textsf{Reporting: `r 2+2`} but this doesn't work. Is there another way that I can get this value? Passing in a parameter is fine if that's possible. Thanks! You have to knit file.tex . I suggest you rename file.tex , e.g., to file.Rnw , and in your main R Markdown document: ```{r, include=FALSE} writeLines(knitr::knit_child('file.Rnw'), 'file.tex') ``` 来源: https://stackoverflow.com

What is this knitr magic that produces a plot by calling <<plot_this>>?

一笑奈何 提交于 2019-12-05 13:44:22
I am trying to work out how this report on a STAN model for the 2016 US presidential elections is generated using rmarkdown : https://raw.githubusercontent.com/pkremp/polls/master/report.Rmd I have looked at the source code available on github , which contains lines like: # Electoral College ```{r echo=FALSE, message=FALSE, fig.align='center'} <<plot_ev>> ``` The command <<plot_ev>> seems to generate plots from code in graphs.R : # Not accounting for the EV allocation rules of Nebraska and Maine # @knitr plot_ev ggplot() + geom_histogram(data = data.frame(ev = result_ev_all_states), aes(ev,

R Markdown horizontal rule that will also work with LaTeX pdf?

给你一囗甜甜゛ 提交于 2019-12-05 13:39:48
I am aware that *** is Pandoc's Markdown for a horizontal rule. This horizontal line looks good on HTML, but if I knit my Markdown into a pdf the horizontal rule only runs half the width of the pdf, and it is centered. This combination just makes the horizontal rule look plain ugly. How do I properly put a horizontal rule in my R Markdown that can render properly to both HTML and pdf? Properly == full length/full width . And while I'm at it, can I format the horizontal rule (color, thickness, etc.) without getting into much CSS which I know nothing about. Make a tex file, say header.tex ,

If-Else Statement in knitr/Sweave using R variable as conditional (Part 2)

若如初见. 提交于 2019-12-05 13:22:07
I am extending a question I posted here: If-Else Statement in knitr/Sweave using R variable as conditional I would like to use an if-else syntax in LaTeX so that, depending on the value of an R variable (say x), one of two LaTeX text paragraphs are output. If x>0, then the LaTeX paragraph has a figure and a table. However, if x<0, then the LaTeX paragraph has just a figure (and no table). I have a MWE that works and is based on the checked answer at the previous post: \documentclass[12pt,english,nohyper]{tufte-handout} \usepackage{tabularx} \usepackage{longtable} \begin{document} <<setup, echo

sourcing References in rmarkdown: workaround

若如初见. 提交于 2019-12-05 13:17:26
I am working with markdonw v2, the rmarkdown package. Throughout the .Rmd file, I create links to websites or images [Link1][pathLink1] ![Image1][pathImage1] then, at the end of the document I give the references [pathLink1]:http://website.com/linkes/Link1.md ![pathImage1]:./images_rmd/ There are other reports that talk about the same citation and use same images in different contexts. I would like to create a separate file containing all the links and path difinitions, so that I could simply source it at the end of each .Rmd file, like I would call in an R environment source(/Rcode1.R)

Save knitr chunk to R file

半城伤御伤魂 提交于 2019-12-05 13:06:20
In knitr there is a read_chunk function which read external code into a chunk. Is it possible to reverse the process. That is, make a function write_chunk() which save the source code in the chunk to an R file? The file name may the same as the chunk name. I found a solution using hooks. Add the following hook: knit_hooks$set(write_chunk = function(before, options, envir) { if (before) { fileConn<-file(paste0("chunk_",options$label,".R") ) writeLines(options$code, fileConn) close(fileConn) } }) and use option <<chunk-name, write_chunk=TRUE>> in the header of a chunk. You can use the following

Knitr - stop superscript in R Markdown

不问归期 提交于 2019-12-05 12:18:28
I need to stop superscript before comma - , or full stop - . . When converting the Rmd file to HTML knitr makes comma superscripted as well. Example: example.Rmd MyTitle ======================================================== J.Smith^1, K.John^2, H.Gone^*. example.html Let me know if this was asked before, I can't find relevant questions. gagolews You may insert HTML tags directly to Markdown documents. To toggle the "superscripting" mode, use sup . MyTitle ======================================================== J.Smith<sup>1</sup>, K.John<sup>2</sup>, H.Gone<sup>*</sup>. EDIT : You may also

how to include an abstract in a rmakdown Rmd file

最后都变了- 提交于 2019-12-05 11:09:56
In a .Rmd file with the header below, I want to include an abstract, so I tried the standard LateX article form, \abstract{This paper explores a variety of topics related to the question of testing the equality of covariance matrices in multivariate linear models, particularly in the MANOVA setting. The main focus is on graphical methods that can be used to understand features of data related to this question.} But, surprisingly (I know this seems weird), the references in my References section become badly formatted -- no spacing between references, odd indentations. So, how can I include

Render code for google chart in rmarkdown Rmd

喜欢而已 提交于 2019-12-05 10:16:37
Google has some nifty charts. I'm sure there's nice R wrapper packages to do what I want but I want to learn how to include a google chart myself as it will likely be more flexible than an R wrapper for including a google chart. Below is an .Rmd that has a donut function to produce the donut from Google chart gallery . The function outputs a code as expected seen below but to actually knit this results in the following pandoc conversion error. How do I include the google chart code properly in an Rmarkdown .Rmd file? Error output file: ttt.knit.md pandoc.exe: Could not fetch https://www