1

I want to save the matrix of values that the barplot() command returns into a variable, but I don't want the plot window:

x <- 1:5
b <- barplot(x)  # this opens a window with the barplot

I have seen the answers that suggest to create a new function from the barplot function or to send the graphic to a "NULL file", but I'm not happy with either of these options.

Isn't there a way to tell a plot function not to plot, but only return its values? In the same way that you can use type = "n" to suppress the points and axes = FALSE to suppress the axes.

I was also thinking of lm(), which outputs the results, and lm0 <- lm(), which doesn't. Here, assigning the function to a variable suppresses any output to the GUI.

1 Answers1

3

You can specify the plot argument to barplot

b <- barplot(x, plot=FALSE)
G5W
  • 36,531
  • 10
  • 47
  • 80
  • I knew it! I thought I had tried this and that it didn't work. Don't know what mistake I made. Thank you! –  Jul 14 '18 at 17:32