Youtube Channel: https://www.youtube.com/c/TechAnswers88
1.Create vector graphics charts using GGPLOT. 2.Use Officer package to create a powerpoint presentation and embed the charts directly. 3. Manipulate the charts in powerpoint.
The advantage of a vector chart is that it can be scaled to any size for your screen or for a life-sized poster or at the side of a truck.
The .png or .jpg saved images of the charts are not suitable for scaling up and get distorted. Where as the vector charts created by the following technique are individual components and can be edited as much as you can in PowerPoint.
Video link https://youtu.be/ewh0Oh5nudc
# Libraries used
library(ggplot2)
library(rvg)
library(officer)
pl <- ggplot(data = mpg,aes(x= manufacturer))
pl <- pl + geom_bar(stat="count")
pl <- pl + geom_text(aes(label = ..count..), stat= "count", vjust = -0.5) # adding data labels
pl <- pl + theme_minimal()
pl <- pl + labs(title ="My title")
pl <- pl + labs(subtitle ="My subtitle")
pl <- pl + labs(caption ="My caption")
pl <- pl + labs(x ="Car Brand", y = "Count")
pl
myplot <- dml(ggobj = pl
,bg = "white"
,pointsize = 12
,editable = TRUE)
doc <- read_pptx()
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <- ph_with(doc, myplot, location = ph_location_fullsize())
# If you want to create multiple charts then create your second chart and call it myplot2
#doc <- add_slide(doc, "Title and Content", "Office Theme")
#doc <- ph_with(doc, myplot, location = ph_location_fullsize())
fileout <- "d:\\tmp\\vectorGraphics.pptx"
print(doc, target = fileout)