I'd like to ggsave
a plot into my clipboard without leaving RStudio, on Windows. Something similar has been asked about for base R graphics, but I'd like to use ggplot
+ggsave
.
example plot operation:
library(tidyverse)
{
ggplot(data = mtcars, aes(y = mpg, x = wt)) + geom_point()
} %>%
ggsave("plot.png", .)
It isn't hard, of course, to navigate to working directory/plot.png in file explorer, right-click the file and copy it, but that takes extra clicks and time.
One possible strategy might be to try and copy into the clipboard with a system()
call afterward, e.g.:
library(tidyverse)
{
ggplot(data = mtcars, aes(y = mpg, x = wt)) + geom_point()
} %>%
ggsave("plot.png", .) %>%
{system( # windows command here)}
but I'm having trouble finding the right windows command, at least without downloading additional utilities. Since base R's savePlot()
is able to save into the clipboard, there should be some way to do this, right?