Export images from R to word - r

I have a code in R with a lot of plots. Copying those plots to a word document manually is too much work, so I am looking for some code that exports those plots directly to a word document. I have tried to use the officer package, but I do not understand it well. I think that with a simple example it will be easier to understand it for me.
For example, suppose I have a code with two easy plots:
plot(1,2)
plot(0,0)
How can I create a word document in which this two plots appear? Thank you very much!

Related

How to prepare publication-quality plots and use calligraphic fonts in Gnuplot?

I use Gnuplot for most of my plots and save the plots as a png. But the resolution of the plots are not so good to put in research papers. So, I need help regarding the following two things:
How to prepare publication-quality plots (eps) in Gnuplot?
How to use calligraphic fonts in the plot, like those written using \mathcal{} in latex?
I searched on the internet regarding these two things, but could not get any ideas.
Thanks in advance.
Since you are stating LaTeX code in your question, I suppose that a solution including LaTeX is suitable for you. I am using gnuplot for producing publication-quality plots (and even TOC-figures!) too, and for me the most convenient method is to use the cairolatex standalone terminal, use LaTeX syntax (e.g. \mathcal{}) in the labels, plot titles and so on, and to compile the figures with pdfLaTeX. Often enough, journals accept figures not only in .eps, but also in .pdf format. If a journal was to refuse .pdf, I would simply convert the figure in the end (i.e. right before submission) to .eps, .png or whatever.

Rasterize plot when using PDF output device

Hello everybody out there using R,
When putting multiple plots with thousands of data points into a single PDF file, this file can get huge and take a long time to open.
The following post describes exactly the same problem in Matplotlib, as well as a nice fix for it:
Matplotlib: multipage PDF with rasterized plots
Particularly nice about it is, that it only rasterizes the points without rasterizing the labels.
http://www.astrobetter.com/blog/2014/01/17/slim-down-your-bloated-graphics/ contains a nice example of it.
I am now looking for a similar solution in R.

Using ggplot to plot a customizable table of data

This idea has been spurred by this work at Five Thirty Eight.
I'm not entirely sure that they used R, but the chart appears in a similar fashion to their other data viz. I looked around here, but couldn't find anything directly relating to this.
Is this kind of plot possible using ggplot?
Thanks for any and all help!
They do use R but their ggplot2 theme is semi-proprietary and they don't say what they use. People have attempted to recreate the theme
https://github.com/jrnold/ggthemes
After the graphs are created it then goes through an illustrative step to bring graphs together and make them more of a story.

TikZ takes more than max LaTeX memory for complex R plot

I have a very complex plot, containing about 56,000 data points. It doesn't look right if I downsample it, so I really need to keep all of them. I would additionally like to add LaTeX captions to the figure. (The expression syntax, IMO, does not produce satisfactory rendering.)
After doing some digging around, TikZ seemed like the way to do it. But I found that it ran out of memory trying to plot the figure. I followed all of the advice I could find for TikZ memory management: this amounted to (1) using externalize and (2) increasing the main_memory for LaTeX to the maximum value (~12M). (I am using MacTeX 2014.) Neither of these solutions seemed to work.
At this point, having looked over SO and some other message boards, I am aware of only two options:
Switch to an alternate TeX interpreter, such as LuaTeX, which will allow me to use more memory, or
Use the native R plot, and then manually superimpose the desired labels onto the figures.
I consider (1) to be an acceptable solution, but the fact that I would need an alternate product makes me wonder if I am missing something. I wonder if there is a way to render complex native R plots, which happen to have TeX-style labels in them.

SVGAnnotation to create tool tips for each value in R heatmaps

I'd like to create a heat map in R that I want to use on a website. I stumbled upon the SVGAnnotation package which seems to be very nice to process SVG graphics in R to make them more interactive. First, I was planning to add tool tips for each cell in the heatmap - if the user hovers over the cell, the value of this cell should pop up. However, I am fighting with SVGAnnotation for more than 3 hours now, reading and trying things, and I can't get it to work.
I would appreciate any help on the SVGAnnotation tool tip function. But I would also very much appreciate alternatives to SVGAnnotation to add some activity to my R SVG heatmap.
So, what I have got so far looks like this:
library(SVGAnnotation)
data(mtcars)
cars <- as.matrix(mtcars)
map <- svgPlot(heatmap(cars))
addToolTips(map, ...) # problem
saveXML(map, "cars.svg")
My problem is the addToolTips function itself, I guess. Intuitively, I would simply insert the data matrix, i.e., cars, but this does not work and R gets stuck (it's calculating, but doesn't return anything, I waited 50 minutes)
EDIT:
After some more online research, I found a good example of what I want to achieve: http://online.wsj.com/article/SB125993225142676615.html#articleTabs=interactive
This heat map looks really great, and the interactive features (tool tips) work very well. I am wondering how they did that. To me, it looks like the graphic was done in R using the ggplot package.
I wrote a command line tool that can do exactly that if you are still interested to add tool tips to your heat map. It runs in Windows/Linux/MacOS terminals. All you need as input is the heat map as svg file and the data table/matrix that you used as input to create your heat map as csv or other text file.

Resources