在 R 中禁用绘图显示 [英] Disable plot display in R

查看:49
本文介绍了在 R 中禁用绘图显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关闭 R 中绘图的显示.

I am trying to turn off the display of plot in R.

我阅读了 禁用 GUI、R 中的图形设备 但唯一的解决方案给出的是将绘图写入文件.

I read Disable GUI, graphics devices in R but the only solution given is to write the plot to a file.

如果我不想污染工作区,如果我没有写权限怎么办?我试过 options(device=NULL) 但没有用.

What if I don't want to pollute the workspace and what if I don't have write permission ? I tried options(device=NULL) but it didn't work.

上下文是 NbClust 包:我想要 NbClust() 返回的内容,但我不想显示它所做的绘图.

The context is the package NbClust : I want what NbClust() returns but I do not want to display the plot it does.

提前致谢!

这是一个使用来自rattle包的数据的可重现示例:)

edit : Here is a reproducible example using data from the rattle package :)

data(wine, package="rattle")
df <- scale (wine[-1])

library(NbClust)

# This produces a graph output which I don't want
nc <- NbClust(df, min.nc=2, max.nc=15, method="kmeans")

# This is the plot I want ;)
barplot(table(nc$Best.n[1,]), 
    xlab="Numer of Clusters", ylab="Number of Criteria",
    main="Number of Clusters Chosen by 26 Criteria")

推荐答案

您可以将通话包裹在

pdf(file = NULL)

dev.off()

这会将所有输出发送到一个有效隐藏它的空文件.

This sends all the output to a null file which effectively hides it.

这篇关于在 R 中禁用绘图显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆