Issue when generating a PowerPoint with geom_raster and ph_with_vg

Hello,

I am running into an issue when generating a PowerPoint file and trying to insert a ggplot diagram with the rvg::ph_with_vg function when the ggplot contains a geom_raster() plot.
Indeed, as soon as I use geom_raster in a diagram, the slide in which I write it contains a “This picture can’t be displayed”.
This seems to be an issue of RStudio Server Pro (I am using the version 1.1.442), because it renders perfectly when running under the RStudio application (on a laptop).

Below, I have pasted a testing script, to reproduce the issue, and tried to make it as short as possible.
This script generates 2 ggplots :
gg_plot, which will contain an empty chart
gg_plot2, which will contain a geom_raster chart, causing the “This picture can’t be displayed” in PowerPoint

So, in summary, as soon as I use geom_raster, it is not possible to generate a vectorized chart on RStudio Server Pro 1.1.442.

Anyone has a clue why it doesn't work ?

Thanks a lot for your help.
Best regards
Yves Peneveyre

##Code
library(readxl)
library(data.table)
library(birk)
library(officer)
library(viridis)
library(dichromat)
library(fields)
library(ggplot2)
library(RColorBrewer)
library(dplyr)
library(rvg)
library(dplyr)
library(shinyjqui)
library(ggrepel)
library(rlist)
library(plotly)


# Preparting a data frame    
df <- data.frame(matrix(ncol = 3, nrow = 0))
x <- c("Var1", "Var2", "max")
colnames(df) <- x

for(i in 1:5)
{
  df[i, "Var1"] <- -1
  df[i, "Var2"] <- -0.1 * i
  df[i, "max"] <- 0.93
}

gg_plot <- ggplot()
gg_plot <- gg_plot + geom_hline(yintercept = 0,  color = "grey", size=0.1)
gg_plot <- gg_plot + geom_vline(xintercept = 0,  color = "grey",size=0.1)

# the geom_raster will generate an empty png file
gg_plot2 <- gg_plot + geom_raster(data = df, aes_string(x = "Var1", y = "Var2", fill = "max"))


read_pptx() %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  # Because gg_plot does not contain any geom_raster instruction, it will generate the graphic
  rvg::ph_with_vg(code = print(gg_plot)) %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  # This one will display a broken image in PPTX
  rvg::ph_with_vg(code = print(gg_plot2)) %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  # This one will generate the non-vectorised image
  ph_with_gg(gg_plot2) %>%
  print("~/test.pptx")

I don't have an immediate answer, but if possible it would be worth trialing the preview release to see if things are better in the v1.2 branch, which we're hoping to promote to final release soon.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.