Disable plot display in R

后端 未结 2 1072
小鲜肉
小鲜肉 2021-01-23 03:47

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

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

What if I

2条回答
  •  我在风中等你
    2021-01-23 04:05

    Luckily it seems that NbClust is one giant messy function with some other functions in it and lots of icky looking code. The plotting is done in one of two places.

    Create a copy of NbClust:

    > MyNbClust = NbClust
    

    and then edit this function. Change the header to:

    MyNbClust <-
        function (data, diss = "NULL", distance = "euclidean", min.nc = 2, 
                  max.nc = 15, method = "ward", index = "all", alphaBeale = 0.1, plotetc=FALSE) 
    {
    

    and then wrap the plotting code in if blocks. Around line 1588:

        if(plotetc){
            par(mfrow = c(1, 2))
            [etc]
            cat(paste(...
        }
    

    and similarly around line 1610. Save. Now use:

     nc = MyNbClust(...etc....)
    

    and you see no plots unless you add plotetc=TRUE.

    Then ask the devs to include your patch.

提交回复
热议问题