I am working on transfering my plots to a presentation using officer
package in R.
A ggplot can be transferred using the ph_with_gg()
function but what is the function to transfer normal R plots? I am not finding any such function in the package.
These are few of the resouces that I am refering:
PowerPoint presentations generation
Your help will be appreciated!
Regards
Save the plot you want to output as, say, a png file then use the ph_with_img
function to place the image into your presentation.
The on-line help for the Powerpoint component of officer shows how to do this - see https://davidgohel.github.io/officer/articles/powerpoint.html which you already referred to in your post.
If you don't know how to save a plot as an image please see (for example) this thread: how to save a plot as image on the disk
I have found a way of doing this using officer
and rvg
packages together.
rvg also allows us to edit our plots on the slides.
The simple code to save a plot on slides is
ppt <- ph_with_vg(ppt, code = plot(), type = "body")
If you would like to export R graphs to Powerpoint you can also use the wrapper package export
built on top of officer
that just came out on CRAN, see https://cran.r-project.org/web/packages/export/index.html and for demo https://github.com/tomwenseleers/export
Typical syntax is very easy and works for either base R, ggplot2 or lattice graphs, eg for a ggplot2 plot (but syntax is the same for base R plot, just call it after you made the plot):
install.packages("export")
library(export)
library(ggplot2)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species,
size = Petal.Width, alpha = I(0.7))
graph2ppt(file="ggplot2_plot.pptx", width=6, height=5)
You can also use it to export to Word, Excel, Latex or HTML and you can also use it to export statistical output of various R stats objects.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.