0

Is it possible to assign plot() output in the same way as ggplot2 output?

e.g.

my_plot <- plot(c(1,2,3))

my_plot
# [1] NULL

The above doesn't work, but the following (for ggplot) does:

library(ggplot2)
my_ggplot <- ggplot(mapping = aes(x = 1:3, y = c(1,2,3))) + geom_point()

# Running this will show the plot
my_ggplot
stevec
  • 41,291
  • 27
  • 223
  • 311

2 Answers2

1

You can use recordPlot() method

Check This Answer Save a plot in an object

Marwan Mostafa
  • 403
  • 4
  • 12
0

In case it's useful, here's an extremely simple example that works

plot(1:15) # make plot
p <- recordPlot() # assign plot
p # view plot
stevec
  • 41,291
  • 27
  • 223
  • 311