简体   繁体   中英

Suppress plot window in R when saving output of plot command to variable

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.

您可以将plot参数指定为barplot

b <- barplot(x, plot=FALSE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM