Aller au contenu

Our posts tagged

Package

What's new in flextable 0.9.11

flextable 0.9.11 brings ‘patchwork’ integration to combine tables with plots and Quarto markdown support inside cells with as_qmd().

Read

tabular and flextable

tables::tabular() is the closest thing to the PROC TABULATE in the current R ecosystem. The as_flextable() function of the ‘flextable’ package allows you to obtain a table from the result of tables::tabular() which can then be formatted and integrated into a document of your choice.

Read

flextable supports RTF

The post presents the new RTF output supported by the ‘flextable’ package and shows an illustrated example.

Read

flextable for 'Grid graphics'

In this article we present the graphic output generated by flextable and how to take advantage of it with ‘ggplot2’ or ‘grid’.

Read

flextable 0.7.2 is out

An illustrated summary of the new features of the ‘flextable’ package: how to create crosstabulations of aggregations, how to use flextable for printing data.frame in R Markdown documents and how to split column names into multiple lines.

Read

News from ggiraph

ggiraph has a new syntax easier to use than the old one, the JavaScript code has also been completely modularized. In this post, we are summarising what ggiraph can do and then we are explaining what are the new functionalities.

Read

flextable 0.4.0 is out

The package flextable is existing since mid 2016 and I did not made any communication about it; obviously if I wrote it, I’d like it to be used by R users! That post is an attempt to fix that.

The flextable package makes it simpler to create tables for reporting purposes. The goal of the package is to provide a set of functions that can be used to design and format tabular reporting.

Read

officer version 0.1.6

It’s time to announce the release of officer version 0.1.6. It allows to generate Microsoft documents from R; supported formats are Word and PowerPoint. It does come with other new packages1:

  • flextable: produces sophisticated tables.
  • rvg: produces vector graphics for PowerPoints
  • mschart: produces native Microsoft charts

Package officer is the reboot of ReporteRs. It’s better, faster and does only rely on R.2

Example

Let’s have a demo. I have made a video for impatients:

First load packages:

library(officer)
library(flextable)
library(rvg)
library(mschart)
library(magrittr)
library(ggplot2)

We will use the following dataset:

Download file data.RDS

data <- readRDS(here("static/files/melanoma.RDS"))
regulartable(data) %>% theme_vanilla() %>% autofit() 

Status

Gender

Ulceration

n

Mean

SD

Alive

Female

Absent

68

1.693

2.004

Alive

Female

Present

23

2.972

2.593

Alive

Male

Absent

24

1.468

1.719

Alive

Male

Present

19

4.319

2.423

Melanoma

Female

Absent

8

2.139

1.184

Melanoma

Female

Present

20

4.724

4.128

Melanoma

Male

Absent

8

3.266

4.681

Melanoma

Male

Present

21

5.143

2.862

Non-melanoma

Female

Absent

3

1.667

1.141

Non-melanoma

Female

Present

4

3.302

3.713

Non-melanoma

Male

Absent

4

2.420

2.499

Non-melanoma

Male

Present

3

8.053

4.019

First let’s create a ggplot object:

gg <- ggplot(data, aes(x = Ulceration , y = Mean, colour = Gender, size = n)) + 
  geom_point() + 
  facet_wrap(~Status ) + 
  theme_minimal()
gg

Then a summary table:

ft <- regulartable(data = head(data)) %>% 
  theme_booktabs() %>% 
  set_header_labels( n = "#", Mean = "\u03D1", SD = "\u03C3") %>% 
  color(i = ~ n < 4, color = "wheat") %>% 
  autofit() 
ft

Status

Gender

Ulceration

#

ϑ

σ

Alive

Female

Absent

68

1.693

2.004

Alive

Female

Present

23

2.972

2.593

Alive

Male

Absent

24

1.468

1.719

Alive

Male

Present

19

4.319

2.423

Melanoma

Female

Absent

8

2.139

1.184

Melanoma

Female

Present

20

4.724

4.128

A Microsoft chart:

scatter_ms <- ms_scatterchart(data = data, x = "Mean", y = "n", group = "Status")

And gather them in a new PowerPoint document:

read_pptx() %>% 
  # add a slide then the flextable
  add_slide(layout = "Title and Content", master = "Office Theme") %>% 
  ph_with(ft, location = ph_location_type(type="body") ) %>% 
  # add a slide then the ggplot
  add_slide(layout = "Title and Content", master = "Office Theme") %>% 
  ph_with(dml(code = print(gg)), location = ph_location_type(type="body")) %>% 
  # add a slide then the microsoft chart
  add_slide(layout = "Title and Content", master = "Office Theme") %>% 
  ph_with(scatter_ms, location = ph_location_type(type="body")) %>% 
  # generate pptx
  print(target = here("static/files/melanoma.pptx")) %>% 
  invisible()

Download file melanoma.pptx - view with office web viewer

Read

ggiraph 0.3.3 is out

I am excited to announce the release of ggiraph version 0.3.3.

The package did not evolved that much within the last months as I was busy on other projects. I finally found time last week to work on it.

  • The new version fixes an issue with pan effect (that was not adjusted to the zoom level).
  • ggiraph() has a new agument ggobj to avoid call to print in the code argument.
  • Widget sizing has been improved

Let’s have simple examples with the following ggplot object.

Read