1

Is there a way to insert images, in this case ggplot2 charts, into a Google Sheet, using an R script? Maybe using the googlesheets package?

I see how to add an image to an Excel spreadsheet and I can add an image to a Google Sheet in my browser via Insert -> Image in the Sheets menus. But I'd like to add the image to my sheet from within an R script.

Sam Firke
  • 21,571
  • 9
  • 87
  • 105

1 Answers1

2

This is a bit of a hack, and it seems the image will take exactly the size of one cell by default. But it is a way to insert images:

x <- gs_edit_cells(ss=x, ws="y", input='=IMAGE("https://i.stack.imgur.com/FrDZc.jpg")')

You can then manually from within Google Sheets resize the cell and thus the image as well.

Of course the new problem is now how to give an image a web-address from within R --- but I wouldn't think that is too hard.

s_baldur
  • 29,441
  • 4
  • 36
  • 69
  • 1
    This worked! And actually the `IMAGE()` function takes values for `mode`, `height`, and `width` so you can insert the image at the size you want. E.g., `x <- gs_edit_cells(ss=x, ws="y", input='=IMAGE("https://i.stack.imgur.com/FrDZc.jpg", 4, 800, 1200)')` – Sam Firke May 09 '18 at 20:46