Nous travaillons toujours sur le dataset df
calculé à l'exercice précédent.
À l’aide de l’aide mémoire ggplot2 :
fill
de la fonction aes()
pour améliorer le graphique aes()
) library(dplyr) df <- read.csv(file = system.file("extdata", "Base_synth_territoires.csv", package = "savoirfR"), header = TRUE, sep = ";", dec = ",", fileEncoding = "latin1", colClasses = c(rep("character", 2), rep("factor", 4) , rep(NA, 32))) %>% mutate(densite = P14_POP / SUPERF, tx_natal = 1000 * NAISD15 / P14_POP, tx_mort = 1000 * DECESD15 / P14_POP)
Résultat attendu :
library(dplyr) df <- read.csv(file = system.file("extdata", "Base_synth_territoires.csv", package = "savoirfR"), header = TRUE, sep = ";", dec = ",", colClasses = c(rep("character", 2), rep("factor", 4) , rep(NA, 32))) %>% mutate(densite = P14_POP / SUPERF, tx_natal = 1000 * NAISD15 / P14_POP, tx_mort = 1000 * DECESD15 / P14_POP)
library(ggplot2) ggplot(data = df, aes(x = P14_POP)) + geom_histogram() # Ce n'est pas très informatif, avec une transformation log, on y voit plus clair ! ggplot(data = df, aes(x = log(P14_POP))) + geom_histogram() # barplot ggplot(data = df, aes(x = REG)) + geom_bar() # améliorer avec le paramètre `fill` ggplot(data = df, aes(x = REG, fill = REG)) + geom_bar() # nuage de points ggplot(data = df, aes(x = densite, y = tx_mort)) + geom_point() # ajout couleur ggplot(data = df, aes(x = densite, y = tx_mort, color = REG)) + geom_point()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.