1

I am trying to change the height and width of an image with no success. The image needs to be put in an powerpoint presentation which works just fine. But for some reason it keeps stretching the image across the slide.

After creating the image and saving it into an powerpoint presentation I get this. If you look at the letters they seem stretched. example1

What I realy want is like the following example. example2

I understand that this could be done manualy for every image in the powerpoint presentation by simply adjusting the image. But as I need to create more than just one powerpoint, It is not realy desired to do it manualy.

The code I use to save the image:

#-------------------------------------------------#
#--------Create grid list of all graphs-----------#
#-define the rows of which the graphs are ordered-#
#-------------------------------------------------#
Finangrid <- grid.arrange(
  fig1, fig2, fig3,
  nrow = 1
)
#-------------------------------------------------#
#-------------Save grid list to file--------------#
#----------It creates file if not exist-----------#
#-------------------------------------------------#
ggsave("Financieel.png", 
       plot = Finangrid, 
       device = "png",
       scale = 2,
       width = 7, 
       height = 5, 
       units = c("in")
)

And the code to export the image into an powerpoint presentation:

loc_body1 <- ph_location_type(type = "body", position_right = TRUE, position_top = TRUE)
loc_body2 <- ph_location_type(type = "body", position_right = FALSE, position_top = TRUE)

doc <- read_pptx("prestest.pptx")
doc <- doc %>% on_slide(index = 24) %>%
  ph_with(external_img("Financieel.png"), location = loc_body1)
fileout <- "prestest.pptx"
print(doc, target = fileout)
Robbie Voort
  • 121
  • 6
  • 1
    It would be helpful if you could provide a reproducible example (https://stackoverflow.com/help/minimal-reproducible-example). That being said, my guess at what you need would be to set the "units" argument as well as the width and height. If you want a certain number of pixels, then you can specify `units = "mm"` So, it would be something like this: `ggsave(filename = "Plot 1.png", width = 480, height = 756, units = "mm")` That would save the last plot sent to the graphics device as "Plot 1.png" with a width of 480 pixels and a height of 756 pixels. – Liz Page-Gould Apr 09 '21 at 13:35
  • I forgot to paste the code I use, sorry for that! As you see in my code I already specify the units. I tried your solution (just to be sure) but the result is still a stretched image... – Robbie Voort Apr 09 '21 at 13:46

0 Answers0