Aller au contenu

Nos articles avec le tag

R

Les nouveautés du package flextable 0.4.6

Une nouvelle version du package flextable a été envoyée sur le CRAN. C’est l’occasion de présenter les nouvelles fonctions pour gérer les bordures et les méthodes de formatage des contenus des colonnes.

Consulter

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.

Consulter

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"))
flextable(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 <- flextable(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

Consulter

ggiraph 0.3.3 est sur le CRAN

Je suis content d’annoncer la sortie de la version 0.3.3 de ggiraph.

Etant assez pris, je n’avait pas fait évolué le package depuis quelques mois. J’ai finalement trouvé le temps de travailler dessus.

  • Le pan est maintenant ajusté au niveau du zoom.
  • ggiraph() a un nouvel argument ggobj pour éviter d’avoir à utiliser la fonction print dans l’argument code.
  • La gestion de la taille des graphiques (des htmlwidgets en fait) est grandement améliorée.

Allez, une petite illustration :

Consulter