25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lab01-correction.Rmd 2.0KB

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