Skip to content

markschl/embed_krona

Repository files navigation

Krona charts in R(Studio)

This repo provides a function for creating Krona charts in R.

Features

  • The interactive charts can be explored directly within R-Markdown documents in RStudio and will be embedded into documents rendered to HTML webpages.
  • For document formats like PDF, DOCX, ODT, etc., snapshot images will be inserted.
  • Support for phyloseq objects.
  • Flexible grouping into multiple datasets explored within the same chart
  • Custom coloring schemes

Example

The following snapshot image of a Krona chart gives an overview of the taxa in the GlobalPatterns dataset from phyloseq package. It was generated in the example analysis.

Tutorial

A small tutorial is provided in the example R-Markdown document. Two rendered versions can be downloaded:

For a documentation of all possible options for plot_krona see the R script.

Output notes

Whether interactive charts or static snapshots are embedded depends on whether the plot_krona function is executed from within R-Markdown chunks, in the R console or rendered to different document formats. Snapshots can be enforced with snapshot=TRUE.

interactive chart snapshot image* remarks
Inline view below R-Markdown chunks (Rstudio) yes yes (png) (1) interactive chart size can be changed with iframe_width / iframe_height, but this just adds scrollbars, the viewport does not change. (2) Snapshots (with snapshot=TRUE) can appear too large since expanded to 100% width. (3) out.width / out.height chunk options have no effect
R console yes (in browser) yes (image viewer) set display=FALSE for simple conversion without viewing
HTML (html_document) yes yes (png, pdf) (1) interactive chart: iframe_height modifies the height (e.g. 600px); (2) if snapshots appear too small, either increase snapshot_dim or set out.width (e.g. to 90%) to zoom in.
PDF (pdf_document) - yes (png, pdf) control size with snapshot_dim
DOCX (word_document) - yes (png, pdf) Figures always have the same (incorrect) size
OpenDocument Text (odt_document) - yes (png, pdf) Set out.width to same value as width in snapshot_dim (e.g.: out.width='6in'). Otherwise, the figure will be huge.
RTF text (rtf_document) - yes (png) see ODT
Github Markdown (github_document) (yes) yes See HTML; interactive charts not displayed on Github (use snapshots)

* snapshot_format values can be png, pdf or jpeg, however jpeg rarely works, produces a black background with many formats