Mario kart
Dans ‘Mario Kart 8 Deluxe’ sur la ‘Nintendo Switch’, chaque personnage dispose de caracteristiques, mais contrairement aux karts et aux éléments de personnalisation, elles ne sont pas affichées à l’écran. Ces caracteristiques sont :
- la vitesse (différente en fonction de l’environnement),
- la maniabilité,
- la puissance des mini-turbos,
- la vitesse absolue,
- …
Ces paramètres sont notés sur une échelle qui va de 1 à 6 et ont été répertoriés par la communauté des fans du jeu.
Nous allons utiliser flextable pour présenter le détail de ces statistiques pour chaque personnage.
Les données et images
Les données sont mises à dispositions ici: https://docs.google.com/spreadsheets/d/1g7A-38tn9UAIbB2B3sZI-MpILsS3ZS870UTVMRRxh4Q/edit#gid=0
On ajoute deux colonnes contenant le chemin relatif des images à afficher
plus tard avec la fonction dplyr::mutate(). Ces images sont rangés
dans le répertoire ‘mario’, voici la liste des fichiers qui y sont stockés :
library(here)
## here() starts at /Users/davidgohel/gitprojects/ardata.fr
mario_dir_img <- here(
"content", "flextable-gallery",
"2021-01-12-mario-kart", "mario")
fs::dir_tree(mario_dir_img)
## /Users/davidgohel/gitprojects/ardata.fr/content/flextable-gallery/2021-01-12-mario-kart/mario
## ├── BebeHarmonie.png
## ├── BebeMario.png
## ├── BebePeach.png
## ├── Bowser.png
## ├── Harmonie.png
## ├── KoopaTroopa.png
## ├── Luigi.png
## ├── Mario.png
## ├── MarioMetal.png
## ├── Peach.png
## ├── PeachChat.png
## ├── Star_coin.png
## ├── Tanuki.png
## ├── Toad.png
## ├── Toadette.png
## ├── Waluigi.png
## └── Wario.png
Notez que l’on n’affiche pas toutes les colonnes mais seulement celles qui vont de ‘Characters’ à ‘Accel’.
library(readxl)
library(tidyverse)
mk_file <- here(
"content", "flextable-gallery",
"2021-01-12-mario-kart", "mario-kart.xlsx")
mario_kart <- read_excel(mk_file, skip = 1) %>%
mutate(
image = file.path("mario", paste0(image, ".png")),
star = file.path("mario", star)
)
mario_kart %>% select(Characters:Accel)
Characters | Land_speed | Anti-G_speed | Water_speed | Gliding_speed | Accel |
character | numeric | numeric | numeric | numeric | numeric |
Baby Peach | 2.2 | 2.0 | 2.5 | 2.8 | 4.0 |
Baby Rosalina | 2.2 | 2.0 | 2.5 | 2.8 | 4.2 |
Baby Mario | 2.5 | 2.2 | 2.8 | 3.0 | 4.2 |
Toadette | 2.8 | 2.5 | 3.0 | 3.2 | 4.2 |
Koopa Troopa | 2.8 | 2.5 | 3.0 | 3.2 | 4.0 |
Toad | 3.0 | 2.8 | 3.2 | 3.5 | 4.0 |
Cat Peach | 3.2 | 3.0 | 3.5 | 3.8 | 4.0 |
Peach | 3.5 | 3.2 | 3.8 | 4.0 | 3.8 |
Tanooki Mario | 3.5 | 3.2 | 3.8 | 4.0 | 3.8 |
Mario | 3.8 | 3.5 | 4.0 | 4.2 | 3.5 |
n: 16 | |||||
Création du flextable
library(flextable)
library(officer)
set_flextable_defaults(
font.family = "Arial", font.size = 9,
padding = 2, digits = 1)
var_stat <- setdiff(
names(mario_kart),
c("image", "star", "color", "Characters"))
ft <- flextable(mario_kart, col_keys = c("Characters", var_stat)) %>%
set_header_labels(Land_speed = "Land", `Anti-G_speed` = "Anti-G",
Water_speed = "Water", Gliding_speed = "Gliding") %>%
add_header_row(values = c("Characters", "Speed", "Accel", "Weight",
"Handling", "Traction", "M-turbo"),
colwidths = c(1, 4, 1, 1,
4, 1, 1)) %>%
theme_box() %>%
merge_v(part = "header") %>% bold(part = "header") %>%
valign(valign = "center", part = "header") %>%
mk_par(j = "Characters",
value = as_paragraph(
as_b(
colorize(Characters, color = mario_kart$color)),
as_chunk(" "),
as_image(image, width = 0.2, height = 0.2))
) %>%
colformat_double(digits = 1) %>%
theme_zebra(odd_header = "#c7254e", even_header = "#c7254e",
odd_body = "#fff5f5", even_body = "#f8f9fa") %>%
color(part = "header", color = "white") %>%
align(align = "right", part = "all") %>%
rotate(rotation = "tbrl", part = "header") %>%
valign(valign = "bottom", part = "header") %>%
width(width = .55) %>%
width(j = 1, width = 1.3 )
ft
Characters | Speed | Accel | Weight | Handling | Traction | M-turbo | ||||||
Land | Anti-G | Water | Gliding | Land | Anti-G | Water | Gliding | |||||
Baby Peach | 2.2 | 2.0 | 2.5 | 2.8 | 4.0 | 2.0 | 5.0 | 5.0 | 4.5 | 5.0 | 4.2 | 4.0 |
Baby Rosalina | 2.2 | 2.0 | 2.5 | 2.8 | 4.2 | 2.0 | 4.8 | 4.8 | 4.2 | 4.8 | 3.8 | 4.0 |
Baby Mario | 2.5 | 2.2 | 2.8 | 3.0 | 4.2 | 2.2 | 4.5 | 4.5 | 4.0 | 4.5 | 4.0 | 3.8 |
Toadette | 2.8 | 2.5 | 3.0 | 3.2 | 4.2 | 2.5 | 4.2 | 4.2 | 3.8 | 4.2 | 3.5 | 3.8 |
Koopa Troopa | 2.8 | 2.5 | 3.0 | 3.2 | 4.0 | 2.5 | 4.5 | 4.5 | 4.0 | 4.5 | 4.2 | 3.8 |
Toad | 3.0 | 2.8 | 3.2 | 3.5 | 4.0 | 2.8 | 4.2 | 4.2 | 3.8 | 4.2 | 4.0 | 3.5 |
Cat Peach | 3.2 | 3.0 | 3.5 | 3.8 | 4.0 | 2.8 | 4.0 | 4.0 | 3.5 | 4.0 | 3.8 | 3.5 |
Peach | 3.5 | 3.2 | 3.8 | 4.0 | 3.8 | 3.0 | 3.8 | 3.8 | 3.2 | 3.8 | 3.8 | 3.5 |
Tanooki Mario | 3.5 | 3.2 | 3.8 | 4.0 | 3.8 | 3.2 | 3.8 | 3.8 | 3.2 | 3.8 | 3.2 | 3.5 |
Mario | 3.8 | 3.5 | 4.0 | 4.2 | 3.5 | 3.5 | 3.5 | 3.5 | 3.0 | 3.5 | 3.5 | 3.2 |
Luigi | 3.8 | 3.5 | 4.0 | 4.2 | 3.5 | 3.5 | 3.8 | 3.8 | 3.2 | 3.8 | 3.2 | 3.2 |
Rosalina | 4.0 | 3.8 | 4.2 | 4.5 | 3.2 | 3.8 | 3.2 | 3.2 | 2.8 | 3.2 | 3.8 | 3.2 |
Metal Mario | 4.2 | 4.0 | 4.5 | 4.8 | 3.2 | 4.5 | 3.2 | 3.2 | 2.8 | 3.2 | 3.2 | 3.0 |
Waluigi | 4.5 | 4.2 | 4.8 | 5.0 | 3.2 | 4.0 | 3.0 | 3.0 | 2.5 | 3.0 | 3.0 | 3.0 |
Wario | 4.8 | 4.5 | 5.0 | 5.2 | 3.0 | 4.2 | 2.8 | 2.8 | 2.2 | 2.8 | 3.2 | 2.8 |
Bowser | 4.8 | 4.5 | 5.0 | 5.2 | 3.0 | 4.5 | 2.5 | 2.5 | 2.0 | 2.5 | 3.0 | 2.8 |
Mettre en évidence les meilleurs scores
Ajoutons la pièce dans la colonne où chaque personnage a le score le plus élevé.
for(column in var_stat) {
i_selector <- as.formula(
paste0("~`", column, "`>= max(`",
column, "`, na.rm = TRUE)"))
ft <- mk_par(ft,
i = i_selector, j = column,
value = as_paragraph(
as_image(star, width = .15, height = .15),
as_chunk(" "),
as_chunk(.)), use_dot = TRUE
)
}
ft <- autofit(ft)
ft
Characters | Speed | Accel | Weight | Handling | Traction | M-turbo | ||||||
Land | Anti-G | Water | Gliding | Land | Anti-G | Water | Gliding | |||||
Baby Peach | 2.2 | 2.0 | 2.5 | 2.8 | 4.0 | 2.0 |
|
|
|
|
|
|
Baby Rosalina | 2.2 | 2.0 | 2.5 | 2.8 |
| 2.0 | 4.8 | 4.8 | 4.2 | 4.8 | 3.8 |
|
Baby Mario | 2.5 | 2.2 | 2.8 | 3.0 |
| 2.2 | 4.5 | 4.5 | 4.0 | 4.5 | 4.0 | 3.8 |
Toadette | 2.8 | 2.5 | 3.0 | 3.2 |
| 2.5 | 4.2 | 4.2 | 3.8 | 4.2 | 3.5 | 3.8 |
Koopa Troopa | 2.8 | 2.5 | 3.0 | 3.2 | 4.0 | 2.5 | 4.5 | 4.5 | 4.0 | 4.5 |
| 3.8 |
Toad | 3.0 | 2.8 | 3.2 | 3.5 | 4.0 | 2.8 | 4.2 | 4.2 | 3.8 | 4.2 | 4.0 | 3.5 |
Cat Peach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