How to crop plots with R officer package? - r

When exporting plots to a .docx with the officer package, a lot of white space is created around the plots.
That way it is using up way to much space in the word document. It would be nice to crop the picture to get rid of the white space around the plot, so it looks more like this:
I don't know (1) if I have to set the dimension/size of the plot when I create the plot or (2) when I export the plot to the .docx with officer package.
Because I have a lot of plots that are getting exported (which are roughly of the same content and seize), I am looking for a good way to let them look the same.

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.

Export images from R to word

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!

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.

Is there a way to recover a ggplot2 image from a Plotly image?

I have some code that generates a plotly image in R. Previously I included this plot in a presentation using Rstudio/ioslides. The people I am collaborating with want a version in powerpoint. I am trying to use the ReporterRs package in order to create an re-producible shell powerpoint presentation with all of my plots. However ReporterRs only accepts lattice, ggplot2, and base images. Since there is a way to convert ggplot2 objects to plotly images I was hoping there was a way to go backwards. However I am stuck. I have been unable to "downgrade" my plotly plots to ggplot2. Does anyone know if there is a way to do this?
(I know I can just copy and paste them over but I would like to develop a workflow where I can create easily reproducible and replaceable plots so that I don't have to do very much work if I change the data)

Plotting in R using ggplot2 and latex

I am plotting a bar graph in R and exporting as eps, the plot looks excellent. When i add it to my latex file it messes up the font any recommendations ?
Here is the original eps
Here is the image in the pdf produced in the latex, i am doing
\includegraphics[width=\columnwidth]{file.eps}
Could it be that your controlling the width of the picture which is messing up the aspect ratio? In LaTeX I usually use [scale=.X] and play around a bit until it's the correct size. That way the aspect ratio is kept the same.

Resources