Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R, generate pretty plot by dfSummary

Tags:

r

summarytools

I have a problem using summarytools packet. There is tutorial:https://cran.r-project.org/web/packages/summarytools/vignettes/Introduction.html with pretty plots of data: enter image description here My problem is that my code generate only TEXT GRAPH. This is chunk of code in my markdown to generate plot:

```{r summary, results='markup'}
library(summarytools)
my_data <- ...
dfSummary(my_data)
```

Unfortunately it generates something like this: enter image description here How can I generate this pretty report using summarytools? Or have you better tools for this? (generate graph, mean, std, etc.)


I found the correct syntax to generate plot:

print(dfSummary(baseline_train), method = 'render')

And the results look like this: enter image description here

like image 320
CezarySzulc Avatar asked Jan 16 '19 10:01

CezarySzulc


2 Answers

A little update on this:

  • Always use knitr chunk option results='asis', as someone pointed in an earlier comment.
  • It is possible to generate summaries including png graphs using print():

    print(dfSummary(iris), method = "render")

  • Starting with version 0.9.0 (available only on GitHub as of Feb. 2019), markdown summaries will also include png graphs provided you specify the following arguments:

    • plain.ascii = FALSE
    • style = "grid"
    • a physical location for temporary png's (tmp.img.dir)

      dfSummary(iris, plain.ascii = FALSE, style = "grid", tmp.img.dir = "/tmp")

Additionnal tips

  • In both cases, you will (in all likelihood) need to adjust the size of the graphs with dfSummary()'s graph.magnif parameter (try values between .75 and .85).
  • Exclude a column or two to avoid overly wide summaries:
    dfSummary(iris, [...], varnumbers = FALSE, valid.col = FALSE)
like image 197
Dominic Comtois Avatar answered Oct 05 '22 09:10

Dominic Comtois


You need to use results = 'asis' for the code chunk. Here is minimal reproducible example:

---
title: "Untitled"
output: html_document
---

```{r, results='asis'}
library(summarytools)
dfSummary(iris, plain.ascii = FALSE, style = "grid")
```

produces

enter image description here

like image 30
Maurits Evers Avatar answered Oct 05 '22 10:10

Maurits Evers