knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  echo = TRUE
)

Avant toutes choses

Nous aurons besoin du package pheatmap :

library(pheatmap)

Nous allons également avoir besoin des données fruits :

data("fruits", package = "tidyViz")

Premier essai

pheatmap(fruits)
Error in hclust(d, method = method) : 
  NA/NaN/Inf dans un appel à une fonction externe (argument 10)
De plus : Warning messages:
1: In dist(mat, method = distance) :
  NAs introduits lors de la conversion automatique
2: In dist(mat, method = distance) :
  NAs introduits lors de la conversion automatique

Pourquoi ça ne fonctionne pas ?

Deuxième essai {.columns-2}

pheatmap(fruits[, -(1:2)])

pheatmap(fruits[, -(1:2)])

C'est déjà mieux ?

Les arguments

Pour avoir une liste complète des arguments : ?pheatmap

Troisième essai {.columns-2}

pheatmap(
  fruits[, -(1:2)],
  cluster_rows = FALSE,
  scale = "column",
  show_rownames = FALSE,
  cellwidth = 10
)

pheatmap(
  fruits[, -(1:2)],
  cluster_rows = FALSE,
  scale = "column",
  show_rownames = FALSE,
  cellwidth = 10
)

Comment changer les couleurs ?

Quatrième essai {.columns-2 .smaller}

colfun <- colorRampPalette(
  c("darkorchid", 
    "white", 
    "limegreen"))

pheatmap(
  fruits[, -(1:2)],
  cluster_rows = FALSE,
  scale = "column",
  show_rownames = FALSE,
  cellwidth = 10,
  color = colfun(20)
)

colfun <- colorRampPalette(
  c("darkorchid", 
    "white", 
    "limegreen"))

pheatmap(
  fruits[, -(1:2)],
  cluster_rows = FALSE,
  scale = "column",
  show_rownames = FALSE,
  cellwidth = 10,
  color = colfun(20)
)

Comment ajouter des informations "qualitatives" ?

Cinquième essai {.columns-2 .smaller}

colfun <- colorRampPalette(
  c("darkorchid", 
    "white", 
    "limegreen"))
fruitsDF <- data.frame(
  fruits[,-1], 
  row.names = make.unique(fruits$nom))
annotLignes <- fruitsDF[, "groupe", 
                        drop = FALSE]

pheatmap(
  fruitsDF[, -1],
  cluster_rows = FALSE,
  scale = "column",
  show_rownames = FALSE,
  cellwidth = 10,
  color = colfun(20), 
  annotation_row = annotLignes
)

colfun <- colorRampPalette(c("darkorchid", "white", "limegreen"))
fruitsDF <- data.frame(fruits[,-1], row.names = make.unique(fruits$nom))
annotLignes <- fruitsDF[, "groupe", drop = FALSE]

pheatmap(
  fruitsDF[, -1],
  cluster_rows = FALSE,
  scale = "column",
  show_rownames = FALSE,
  cellwidth = 10,
  color = colfun(20), 
  annotation_row = annotLignes
)

A vous !

Changez la commande suivante pour obtenir un joli graphe.

pheatmap(
  t(fruits),
  scale = "row",
  color = c("black", "black"),
  legend_breaks = c(-6, 0,+6),
  border_color = "pink",
  cellheight = 100,
  cellwidth = 0.1,
  show_colnames = "FALSE"
)


vguillemot/tidyViz documentation built on Dec. 23, 2021, 3:09 p.m.