No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

04-perception.Rmd 8.5KB

hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. ---
  2. title: "Perception : système visuel, marques et canaux, couleurs"
  3. author: "Antoine Neuraz"
  4. date: "10/30/2019"
  5. output:
  6. bookdown::html_document2:
  7. code_folding: hide
  8. ---
  9. ```{r, include=FALSE}
  10. library(ggplot2)
  11. library(tidyverse)
  12. library(see)
  13. library(patchwork)
  14. library(vizoR)
  15. seed = 44
  16. ```
  17. # Perception : système visuel, marques et canaux, couleurs
  18. ## TODO
  19. ## Types de marques
  20. ```{r}
  21. size <- list(100, 2)
  22. min_x <- 0
  23. max_x <- 1
  24. p_color <- generate_dataset_uniform(
  25. dataset_size = size,
  26. min_x = min_x,
  27. max_x = max_x,
  28. seed = seed
  29. ) %>%
  30. ggplot(
  31. data = .,
  32. aes(
  33. x = x,
  34. y = y,
  35. color = group
  36. )
  37. ) +
  38. geom_point(size = 3) +
  39. scale_color_material_d() +
  40. theme_void_complete() +
  41. labs(subtitle= "Couleur")
  42. #p_color
  43. ```
  44. ```{r}
  45. p_angle <- generate_dataset_uniform(
  46. dataset_size = size,
  47. min_x = min_x,
  48. max_x = max_x,
  49. seed = seed
  50. ) %>%
  51. mutate(angle = ifelse(group == "group1", 0, pi / 3)) %>%
  52. ggplot(
  53. data = .,
  54. aes(
  55. x = x,
  56. y = y,
  57. angle = angle
  58. )
  59. ) +
  60. geom_spoke(
  61. radius = 0.04,
  62. size = .8
  63. ) +
  64. theme_void_complete() +
  65. scale_color_material_d() +
  66. ggtitle("Angle")
  67. #p_angle
  68. ```
  69. ```{r}
  70. p_size <- generate_dataset_uniform(
  71. dataset_size = size,
  72. min_x = min_x,
  73. max_x = max_x,
  74. seed = seed
  75. ) %>%
  76. mutate(size = ifelse(group == "group1", 2, 3)) %>%
  77. ggplot(
  78. data = .,
  79. aes(
  80. x = x,
  81. y = y,
  82. size = size
  83. )
  84. ) +
  85. geom_point() +
  86. theme_void_complete() +
  87. scale_size(range = c(1, 3)) +
  88. ggtitle("Taille")
  89. #p_size
  90. ```
  91. ```{r}
  92. p_grey <- generate_dataset_uniform(
  93. dataset_size = size,
  94. min_x = min_x,
  95. max_x = max_x,
  96. seed = seed
  97. ) %>%
  98. ggplot(
  99. data = .,
  100. aes(
  101. x = x,
  102. y = y,
  103. color = group
  104. )
  105. ) +
  106. geom_point(size = 3) +
  107. theme_void_complete() +
  108. scale_color_manual(values = c('group2' = 'black', 'group1' = 'lightgrey')) +
  109. ggtitle("Luminosité")
  110. #p_grey
  111. ```
  112. ```{r}
  113. dt <- generate_dataset_uniform(
  114. dataset_size = size,
  115. min_x = min_x,
  116. max_x = max_x,
  117. seed = seed
  118. ) %>%
  119. mutate(curvature = ifelse(group == "group1", 0, 1))
  120. p_curve <- dt %>%
  121. ggplot(
  122. data = .,
  123. aes(
  124. x = x,
  125. y = y,
  126. xend = x,
  127. yend = y+max_x/10,
  128. curvature = curvature
  129. )
  130. ) +
  131. geom_curve(data = subset(dt, group == 'group1'), curvature = 0) +
  132. geom_curve(data = subset(dt, group == 'group2'), curvature = .7) +
  133. scale_color_material_d() +
  134. theme_void_complete() +
  135. ggtitle("Courbe")
  136. #p_curve
  137. ```
  138. ```{r}
  139. dt <- generate_dataset_uniform(
  140. dataset_size = size,
  141. min_x = min_x,
  142. max_x = max_x,
  143. seed = seed
  144. )
  145. p_box <- dt %>%
  146. ggplot(
  147. data = .,
  148. aes(
  149. x = x,
  150. xend = x+max_x/50,
  151. y = y,
  152. yend = y
  153. )
  154. ) +
  155. geom_point(data = subset(dt, group=='group2'),aes(x = x+max_x/100), shape = 22, size = 4) +
  156. geom_segment() +
  157. #geom_curve(data = subset(dt, group == 'group2'), curvature = .7) +
  158. scale_color_material_d() +
  159. theme_void_complete() +
  160. ggtitle("Encapsulage")
  161. #p_box
  162. ```
  163. ```{r}
  164. p_shape <- generate_dataset_uniform(
  165. dataset_size = size,
  166. min_x = min_x,
  167. max_x = max_x,
  168. seed = seed
  169. ) %>%
  170. ggplot(
  171. data = .,
  172. aes(
  173. x = x,
  174. y = y,
  175. shape = group
  176. )
  177. ) +
  178. geom_point(size = 3) +
  179. #scale_color_manual(values = c('group2' = 'black', 'group1' = 'lightgrey')) +
  180. theme_void_complete() +
  181. ggtitle("Forme")
  182. #p_shape
  183. ```
  184. ```{r}
  185. p_fill <- generate_dataset_uniform(
  186. dataset_size = size,
  187. min_x = min_x,
  188. max_x = max_x,
  189. seed = seed
  190. ) %>%
  191. ggplot(
  192. data = .,
  193. aes(
  194. x = x,
  195. y = y,
  196. fill = group
  197. )
  198. ) +
  199. geom_point(size = 3, shape = 21) +
  200. scale_fill_manual(values = c('group2' = 'black', 'group1' = 'white')) +
  201. theme_void_complete() +
  202. ggtitle("Remplissage")
  203. #p_fill
  204. ```
  205. ```{r encode, fig.height=12, fig.cap='Exemples d\'encodage', fig.align='center'}
  206. p_color + p_angle +
  207. p_size + p_grey +
  208. p_curve + p_box +
  209. p_shape + p_fill +
  210. plot_layout(ncol = 2)
  211. ```
  212. ## Mappings in ggplot
  213. ```{r}
  214. #theme_set(theme_void_real())
  215. aes_pos <- ggplot() +
  216. geom_segment(data = data.frame(x = c(0, 0.5),
  217. xend = c(1, 0.5),
  218. y = c(0.5, 0),
  219. yend = c(0.5, 1)),
  220. aes(x = x, y = y, xend = xend, yend = yend),
  221. arrow = arrow(length = grid::unit(12, "pt")), size = .75) +
  222. annotate("text", .5, 1, size = 8, vjust = 1, hjust = 2.5, label = "y") +
  223. annotate("text", 1, .5, size = 8, vjust = 2, hjust = 1, label = "x") +
  224. theme_void() + theme(legend.position = 'none') +
  225. coord_cartesian(xlim = c(-.2, 1.2), ylim = c(-.2, 1.2)) +
  226. labs(title = 'position')
  227. aes_color <- ggplot() +
  228. geom_tile(data = data.frame(x = 0.15 + .2333*(0:3)),
  229. aes(x, y = .5, fill = factor(x)), width = .2, height = .6) +
  230. theme_void() + theme(legend.position = 'none') +
  231. scale_fill_viridis_d() +
  232. labs(title = 'couleur')
  233. aes_shape <- ggplot() +
  234. geom_point(data = data.frame(x = (.5 + 0:3)/4),
  235. aes(x, y = .5, shape = factor(x)), size = 8, fill = "grey80") +
  236. theme_void() + theme(legend.position = 'none') +
  237. scale_shape_manual(values = 21:24) +
  238. expand_limits(x=c(0,1)) +
  239. labs(title = 'forme')
  240. aes_size <- ggplot() +
  241. geom_point(data = data.frame(x = (.5 + 0:3)/4),
  242. aes(x, y = .5, size = factor(x)), shape = 21, fill = "grey80") +
  243. theme_void() + theme(legend.position = 'none') +
  244. scale_size_manual(values = c(2, 5, 8, 11)) +
  245. expand_limits(x=c(0,1)) +
  246. labs(title = 'taille')
  247. aes_lwd <- ggplot() +
  248. geom_segment(data = data.frame(x = rep(0.05, 4),
  249. xend = rep(0.95, 4),
  250. y = (1.5 + 0:3)/6,
  251. yend = (1.5 + 0:3)/6,
  252. size = 4:1),
  253. aes(x = x, y = y, xend = xend, yend = yend, size = size)) +
  254. theme_void() + theme(legend.position = 'none') +
  255. scale_size_identity() +
  256. labs(title = 'épaisseur de ligne')
  257. aes_ltp <- ggplot() +
  258. geom_segment(data = data.frame(x = rep(0.05, 4),
  259. xend = rep(0.95, 4),
  260. y = (1.5 + 0:3)/6,
  261. yend = (1.5 + 0:3)/6,
  262. linetype = 4:1),
  263. aes(x = x, y = y, xend = xend, yend = yend, linetype = linetype), size = 1) +
  264. theme_void() + theme(legend.position = 'none') +
  265. scale_linetype_identity() +
  266. labs(title = 'type de ligne')
  267. aes_pos + aes_shape + aes_size + aes_color + aes_lwd + aes_ltp +plot_layout(nrow=2)
  268. ```
  269. figure from [https://serialmentor.com/dataviz/aesthetic-mapping.html]()
  270. ## scales in ggplot
  271. ```{r, fig.asp = .2}
  272. df <- data.frame(x = c(1:4))
  273. scale_num <- ggplot(df, aes(x)) +
  274. geom_point(size = 3, color = "#0072B2", y = 1) +
  275. scale_y_continuous(limits = c(0.8, 1.2), expand = c(0, 0), breaks = 1, label = "position ") +
  276. scale_x_continuous(limits = c(.7, 4.4), breaks = 1:5, labels = c("1", "2", "3", "4", "5"), name = NULL, position = "top") +
  277. theme_minimal_grid() +
  278. theme(axis.ticks.length = grid::unit(0, "pt"),
  279. axis.text = element_text(size = 14),
  280. axis.title.y = element_blank(),
  281. axis.ticks.y = element_blank())
  282. scale_color <- ggplot(df, aes(x, color = factor(x), fill = factor(x))) +
  283. geom_point(size = 5, shape = 22, y = 1) +
  284. scale_y_continuous(limits = c(0.8, 1.2), expand = c(0, 0), breaks = 1, label = "color ") +
  285. scale_x_continuous(limits = c(.7, 4.4), breaks = NULL) +
  286. scale_color_manual(values = c("#0082A6", "#4EBBB9", "#9CDFC2", "#D8F0CD"), guide = "none") +
  287. scale_fill_manual(values = c("#0082A6", "#4EBBB9", "#9CDFC2", "#D8F0CD"), guide = "none") +
  288. theme_minimal() +
  289. theme(axis.ticks.length = grid::unit(0, "pt"),
  290. axis.text.x = element_blank(),
  291. axis.text.y = element_text(size = 14),
  292. axis.title = element_blank(),
  293. axis.ticks = element_blank(),
  294. panel.grid.major = element_blank())
  295. scale_shape <- ggplot(df, aes(x, shape = factor(x))) +
  296. geom_point(size = 4, color = "grey30", y = 1, fill = "grey80") +
  297. scale_y_continuous(limits = c(0.8, 1.2), expand = c(0, 0), breaks = 1, label = "shape ") +
  298. scale_x_continuous(limits = c(.7, 4.4), breaks = NULL) +
  299. scale_shape_manual(values = 21:24, guide = "none") +
  300. theme_minimal() +
  301. theme(axis.ticks.length = grid::unit(0, "pt"),
  302. axis.text.x = element_blank(),
  303. axis.text.y = element_text(size = 14),
  304. axis.title = element_blank(),
  305. axis.ticks = element_blank(),
  306. panel.grid.major = element_blank())
  307. scale_num + scale_shape + scale_color + plot_layout(ncol = 1)
  308. ```
  309. figure from [https://serialmentor.com/dataviz/aesthetic-mapping.html]()