summarytools icon indicating copy to clipboard operation
summarytools copied to clipboard

Format error when rendering dfSummary graphs in RMarkdown PDF Output

Open wshropshire opened this issue 6 years ago • 11 comments

Hello Dominic,

Love the updates with the Summarytools package, super helpful!

I'm currently having an issue when I render my dfSummary output where my graphs seem to be misaligned with the appropriate row they are supposed to reside within the grid style when using RMarkdown PDF output:

Screen Shot 2019-05-24 at 10 33 09 AM

However, I don't have this issue if I change my output from pdf_document to html_document. My global settings are:

library(knitr)
opts_chunk$set(comment = NA, prompt = FALSE, cache = FALSE, results = 'asis')
library(summarytools)
st_options(plain.ascii = FALSE,          # This is a must in Rmd documents
            style = "rmarkdown",          # idem
            dfSummary.varnumbers = FALSE, # This keeps results narrow enough
            dfSummary.valid.col = FALSE,
            dfSummary.na.col = FALSE)  # idem

and my dfSummary command is:

###Use of summary tools for preliminary data on the clinical data of patients with sequenced Kpn isolates
#freq(kpn_htx_filter_for_Summary, style = "rmarkdown", cumul = FALSE)
dfSummary(kpn_htx_filter_for_Summary, style = "grid", graph.magnif = 0.82, tmp.img.dir = "/tmp")

I've played around with col widths as well as updated to the latest version of summarytools using devtools, but still get the same result. When using html as an output, it looks perfectly fine. Therefore not a big deal, but a lot of the people I work with freak out if it's not in a PDF format. Anyways, thanks for the help!

wshropshire avatar May 24 '19 15:05 wshropshire

Hi, sorry about the late response, I've been away on vacation. I'll be taking a closer look at this soon!

dcomtois avatar Jun 14 '19 16:06 dcomtois

(in the meantime, a workaround is to use style = "multiline", which should fix the alignment issue while not giving ideal results in terms of graphs)

dcomtois avatar Jun 18 '19 02:06 dcomtois

Still haven't found a solution... Seems like a limitation in Pandoc, will keep an eye open for upcoming changes.

dcomtois avatar Aug 15 '19 02:08 dcomtois

No worries! The html output works well and I’m using summary tools as an initial snapshot of my data so no urgent need. Thanks though!

William C. Shropshire, MPH PhD student, Epidemiology

Research Graduate Assistant UTHealth Graduate School of Public Health | Department of Epidemiology, Human Genetics and Environmental Sciences (DEHGES) Center for Antimicrobial Resistance and Microbial Genomics (CARMiG) at McGovern Medical School 6431 Fannin St. Houston, TX 77030 | MSE R.234 | (830)-708-2542


From: Dominic Comtois [email protected] Sent: Wednesday, August 14, 2019 9:02:24 PM To: dcomtois/summarytools Cc: Shropshire, William C; Mention Subject: Re: [dcomtois/summarytools] Format error when rendering dfSummary graphs in RMarkdown PDF Output (#72)

**** EXTERNAL EMAIL ****

Still haven't found a solution... Seems like a limitation in Pandoc, will keep an eye open for upcoming changes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_dcomtois_summarytools_issues_72-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DAII6DHVUJI6JFBMSVHAYMODQES2LBA5CNFSM4HPQUIPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4KT6ZQ-23issuecomment-2D521486182&d=DwMCaQ&c=bKRySV-ouEg_AT-w2QWsTdd9X__KYh9Eq2fdmQDVZgw&r=aSYF7h3Tvg41I17vOHD9ioHcqKyPaNmGralq-mVquHM&m=CBpyTmshsGfXoHmFFASvSa4pHkxA0vtM4ceup_WE7OM&s=8D3GrKMKYgM75OC6LowpO9FpOUBgqWfV3yAfs2v8N2M&e=, or mute the threadhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AII6DHWW4PNENHK2JETCAPLQES2LBANCNFSM4HPQUIPA&d=DwMCaQ&c=bKRySV-ouEg_AT-w2QWsTdd9X__KYh9Eq2fdmQDVZgw&r=aSYF7h3Tvg41I17vOHD9ioHcqKyPaNmGralq-mVquHM&m=CBpyTmshsGfXoHmFFASvSa4pHkxA0vtM4ceup_WE7OM&s=0GWjFV0CDwybQ4gU09njfTKKY0xnSwhu1_bDfFLi9BY&e=.

wshropshire avatar Aug 15 '19 13:08 wshropshire

Probably not the right place to ask that, but how did you manage to get the style of that table @wshropshire?

Thanks a lot.

gustavobrp avatar Jan 29 '20 21:01 gustavobrp

Finally got it to work, it's not perfect since we redefine the \includegraphics command -- so it could affect negatively other images in the document -- but it's a start! Here it is, starting with the YAML section.

I. YAML Header

For the xelatex engine, it's not mandatory, but there are several advantages to it, so I use it systematically.

  ---
  title: "Data Frame Summaries in PDF's"
  output: 
    pdf_document: 
      latex_engine: xelatex
      includes:
        in_header: ./fig-valign.tex
  ---

II. Included Preamble Tex File

This is the LaTeX code in fig-align.tex:

  \usepackage{graphicx}
  \usepackage[export]{adjustbox}
  \usepackage{letltxmacro}
  \LetLtxMacro{\OldIncludegraphics}{\includegraphics}
  \renewcommand{\includegraphics}[2][]{\raisebox{0.5\height}%
    {\OldIncludegraphics[valign=t,#1]{#2}}}

III. R Code

library(summarytools)
st_options(
  plain.ascii = FALSE, 
  style = "rmarkdown",
  dfSummary.style = "grid",
  dfSummary.valid.col = FALSE,
  dfSummary.graph.magnif = .52,
  tmp.img.dir = "/tmp"
)

define_keywords(title.dfSummary = "Data Frame Summary in PDF Format")
dfSummary(tobacco)

As always, set the knitr chunk option results="asis".

rendered results

dcomtois avatar Dec 30 '20 00:12 dcomtois

Fantastic! I have a dataset that I'm going to test-run this with. Thanks for your continued maintenance of this tool!

wshropshire avatar Jan 09 '21 20:01 wshropshire

@wshropshire You're welcome. Please let me know if all goes as expected! Thx.

dcomtois avatar Jan 10 '21 03:01 dcomtois

Hello Dominic,

Seems like my output still has the same issues with the graphical alignment in PDF format when using summarytools v0.9.8. I'll attach the summary file here.

SM-Bacteria_Summary-.pdf

Best,

Will

wshropshire avatar Jan 10 '21 19:01 wshropshire

Also just to follow-up briefly, when my output is switched to 'html' with dfSummary.graph.magnif = .78 the graphical output looks fine, so again, no worries if you have other issues on your plate. The html output works just fine :)

wshropshire avatar Jan 10 '21 19:01 wshropshire

Can you post a reproducible example with your Rmd with yaml details & included tex pls? Also, make sure your .tex file is in the appropriate directory if using relative path.

dcomtois avatar Jan 11 '21 02:01 dcomtois