Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format error when rendering dfSummary graphs in RMarkdown PDF Output #72

Open
wshropshire opened this issue May 24, 2019 · 11 comments
Open

Comments

@wshropshire
Copy link

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!

@dcomtois
Copy link
Owner

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

@dcomtois
Copy link
Owner

(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
Copy link
Owner

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

@wshropshire
Copy link
Author

wshropshire commented Aug 15, 2019 via email

@gustavobrp
Copy link

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

Thanks a lot.

@dcomtois
Copy link
Owner

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

@wshropshire
Copy link
Author

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

@dcomtois
Copy link
Owner

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

@wshropshire
Copy link
Author

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
Copy link
Author

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 :)

@dcomtois
Copy link
Owner

dcomtois commented Jan 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants