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.

lab02-perception-colors.Rmd 1.7KB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ---
  2. title: "LAB 2: Perception et couleurs"
  3. author: "Antoine Neuraz"
  4. date: "19/11/2019"
  5. output:
  6. xaringan::moon_reader:
  7. css: ['default','css/my_style.css']
  8. lib_dir: libs
  9. seal: false
  10. nature:
  11. ratio: '4:3'
  12. countIncrementalSlides: false
  13. self-contained: true
  14. beforeInit: "addons/macros.js"
  15. ---
  16. ```{r setup, include=FALSE}
  17. knitr::opts_chunk$set(echo = TRUE)
  18. library(ggplot2)
  19. library(showtext)
  20. ```
  21. ---
  22. ## Les couleurs dans ggplot2
  23. ```{r}
  24. dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
  25. ggplot(dsamp, aes(carat, price)) +
  26. geom_point(aes(colour = clarity)) +
  27. scale_color_brewer(palette = "Set3")
  28. ```
  29. ```{r}
  30. ggplot(dsamp, aes(carat, price)) +
  31. geom_point(aes(colour = carat))) +
  32. scale_color_distiller(palette="RdYlBu")
  33. ```
  34. ```{r}
  35. font_add_google("Gochi Hand", "gochi")
  36. showtext_auto()
  37. annotate_color = "grey50"
  38. font_add_google("Schoolbell", "bell")
  39. midpoint = (max(dsamp$carat)-min(dsamp$carat))/2
  40. ggplot(dsamp, aes(carat, price)) +
  41. geom_vline(xintercept = midpoint, color = annotate_color) +
  42. geom_point(aes(colour = carat)) +
  43. scale_color_gradient2(low = "#d8b365",
  44. mid="#f5f5f5",
  45. high="#5ab4ac",
  46. midpoint = midpoint) +
  47. annotate("text",
  48. x=.78, y=15000, hjust=1, srt=40,
  49. label ="this is the midpoint",
  50. family="bell",
  51. color=annotate_color) +
  52. annotate("curve",
  53. x = .8, xend=midpoint-.01, y=15000, yend = 14000,
  54. curvature = -.5,
  55. color=annotate_color ,
  56. arrow=arrow(length = unit(0.03, "npc") )) +
  57. theme_minimal() +
  58. theme(panel.grid.minor = element_blank(),
  59. panel.grid.major.x = element_blank()) + ggthemes::theme_tufte()
  60. ```