You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 line
2.0KB

  1. ---
  2. title: "correction"
  3. author: "Antoine Neuraz"
  4. date: "16/11/2020"
  5. output: html_document
  6. ---
  7. ```{r setup, include=FALSE}
  8. knitr::opts_chunk$set(echo = TRUE)
  9. library(ggplot2)
  10. ```
  11. ## Ouvrir le dataset "mtcars"
  12. ## représenter le "Gross horsepower" en fonction du nombre de cylindres
  13. ```{r}
  14. data("mtcars")
  15. ggplot(data = mtcars,
  16. aes(x = as.factor(cyl),
  17. y = hp)) +
  18. geom_jitter(width = .2)
  19. ```
  20. ## utiliser l'encodage multiple sur le nombre de cylindres
  21. ```{r}
  22. ggplot(data = mtcars,
  23. aes(x = as.factor(cyl),
  24. y = hp,
  25. size = cyl,
  26. color = cyl)) +
  27. geom_jitter(width = .2, alpha = .6) +
  28. theme_minimal() +
  29. theme(legend.position = "none")
  30. ```
  31. ## ajouter l'information du nombre de carburateurs
  32. ```{r}
  33. ggplot(data = mtcars,
  34. aes(x = as.factor(cyl),
  35. y = carb,
  36. size = hp,
  37. color = hp)) +
  38. geom_jitter(width = .2, alpha = .6) +
  39. theme_minimal()
  40. #facet_grid(~as.factor(carb))
  41. #theme(legend.position = "none")
  42. ```
  43. ## Paufiner le plot (axes, titres, thème)
  44. ```{r}
  45. ggplot(data = mtcars,
  46. aes(x = as.factor(cyl),
  47. y = carb,
  48. size = hp,
  49. color = hp)) +
  50. geom_jitter(width = .2, alpha = .6) +
  51. theme_minimal() +
  52. labs(x = "Cylinders",
  53. y = "Carburators")
  54. ```
  55. ## représenter la distribution du nombre de miles per gallon en histogramme
  56. ```{r}
  57. ggplot(mtcars,
  58. aes(x= mpg)) +
  59. geom_histogram(bins = sqrt(nrow(mtcars)))
  60. ```
  61. ## représenter la distribution du nombre de miles per gallon en boxplot
  62. ```{r}
  63. ggplot(mtcars,
  64. aes(x= 1, y= mpg)) +
  65. geom_boxplot()
  66. ```
  67. ## representer la distribution du nombre de miles per gallon en fonction du nombre de cylindres
  68. ```{r}
  69. ggplot(mtcars,
  70. aes(x= as.factor(cyl), y= mpg)) +
  71. geom_violin(fill = "grey70")
  72. ```
  73. ## ajouter les points par dessus la distribution
  74. ```{r}
  75. ggplot(mtcars,
  76. aes(x= as.factor(cyl), y= mpg)) +
  77. geom_violin(fill = "grey70") +
  78. geom_jitter(aes(color = cyl),width = .15)
  79. ```
  80. ## paufiner le plot (axes, titres, thème)