Story time with papa Jamie

index

One cool R package I have been using lately, is ReporteRs. It essentially takes your plots etc and creates a PowerPoint of these. The quality of these are pretty good. This has been really useful for me, as I have been doing a lot of ‘data story boards’ for client presentations. Having a PowerPoint story board of all of my figures allows me to visualise what results I have, and what will be good for a client. If you’re a scientist writing a paper, this package will also come in handy as it will allow you to essentially create a PPT of your plots, diagnostics from these and even tables!

This is the final product here.

#Loading the package
require(ReporteRs)

#Create dummy variables
x=1:200
y=jitter(1:200,50)

#Setting up an lm model
m=lm(y~x)

#Set your working directory
setwd()

# Create a PowerPoint document. This is just an empty pptx doc at the moment
plots = pptx()

#Create your first slide. This will be a title slide
plots = addSlide(plots, "Section Header")
plots = addTitle(plots, "My storyline")

#Create a content slide
plots = addSlide(plots, "Title and Content")
plots = addTitle(plots, "Linear regression diagnostics")

#Wrap the plotting functions inside this wrapper.
#IMPORTANT. Anything you place in here such as functions,
#will not be avialable outside of it. So I suggest just placing
#the plotting stuff in here.
plotlm.diag= function(){
  #So we can have all of the plots on one page
  par(mfrow=c(2,2))

  #Plotting the diagnostics
  plot(m)
}

#This adds the plot to our empty plots Title and Content slide
plots = addPlot(plots, plotlm.diag,vector.graphic = T)
#Create a table output
plots = addSlide(plots, "Title and Content")
plots = addTitle(plots, "My lm output")

#The flextable output of the lm summary
plots = addFlexTable(plots, vanilla.table(data.frame("terms"=row.names(data.frame(summary(m)$coefficients)),
summary(m)$coefficients)))
#Create another content slide
plots = addSlide(plots, "Title and Content")
plots = addTitle(plots, "My plot")

plot1= function(){
  plot(x,y)
 }
plots = addPlot(plots, plot1,vector.graphic = T)

####Create PPT
writeDoc(plots, file = "mystoryline.pptx")

Author: Jamie Samson

I am Head of Data Science and Insights at www.mindfolio.com. I am a lover of R and consider myself an Rtist in data visualisations.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s