rdesctools

Any way to access the plot object generated by DescTools::Desc()?


I am using Desc() from DescTools to describe some variables in a rmarkdown PDF document. The problem is that it generates 3 plots that are kept in line when I knit the document, thus clipping the images.

Example:

dates <- sample(seq(as.Date('1999/01/01'), as.Date('2021/01/01'), by="day"), 1000)

results <- DescTools::Desc(dates)

results

The output contains 3 plots. I can find the individual responses using the list in results[[1]]], but I can't find the plot objects, which I think could be a way to put then one below the other.

Any thoughts?


Solution

  • There are no plot objects in results.

    Instead, when you type results in your console, it invokes the S3 generic print, which in turn dispatches the print.Desc method. By default, print.Desc will call a plotting function based on the "class" member of results, which in your example is "Date". If you type DescTools:::plot.Desc.Date in your console, you will see the function that actually generates the plot every time you print results.

    So there are no plot objects. There is data to create a plot, and whenever you print results to the console, the plots are created by a call to a plotting function.

    The Desc plotting functions seem to have very few options available to allow modifications, so the best option would probably be to use the data inside results to create your own plots. If you wish to see the contents of results without the plots, simply type:

    print(results, plotit = FALSE)
    

    And if you want the three plots one at a time, you can do:

    DescTools:::plot.Desc.Date(results[[1]], type = 1)
    

    enter image description here

    DescTools:::plot.Desc.Date(results[[1]], type = 2)
    

    enter image description here

    DescTools:::plot.Desc.Date(results[[1]], type = 3)
    

    enter image description here