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.

02-types_data.Rmd 4.3KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ---
  2. title: "Types de datasets et types de données"
  3. author: "Antoine Neuraz"
  4. date: "10/30/2019"
  5. output:
  6. bookdown::html_document2:
  7. code_folding: hide
  8. ---
  9. # Types de datasets et types de données
  10. ```{r, include = FALSE}
  11. library(ggplot2)
  12. library(ggraph)
  13. library(vizoR)
  14. library(tidygraph)
  15. library(igraph)
  16. library(patchwork)
  17. ```
  18. ## Types de datasets
  19. ### Données tabulaires
  20. ```{r}
  21. make_tabular_data <- function(x_size, y_size, highlight) {
  22. dt <- data.frame(x = rep(1:x_size, y_size),
  23. y = unlist(lapply(1:y_size, function(x) rep(x, x_size))),
  24. group = rep(1, x_size*y_size))
  25. dt$group[highlight] <- 2
  26. dt
  27. }
  28. ggplot(data = make_tabular_data(5,3,8),
  29. mapping = aes(x = x, y = y, fill = as.factor(group))) +
  30. geom_tile(color = 'white', size = 2) +
  31. annotate("segment", x=0.2,xend=5,y=3.8,yend=3.8,arrow=arrow(type="closed",length= unit(.4,"cm"))) +
  32. annotate("segment", x=0.2,xend=0.2,y=3.8,yend=1,arrow=arrow(type="closed",length= unit(.4,"cm"))) +
  33. annotate("text", x=3, y=0, label = "Cellule contenant une valeur",hjust=0.5) +
  34. annotate("segment", x=3,xend=3,y=0.2,yend=1.5,arrow=arrow(type="closed", length= unit(.4,"cm"))) +
  35. scale_fill_manual(values = list("lightgrey", "darkred"))+
  36. scale_x_continuous(position = "top")+
  37. xlab('Attributs (colonnes)') +
  38. ylab('Items (lignes)') +
  39. theme_elegant() +
  40. theme(legend.position = 'none',
  41. axis.text=element_blank(),
  42. axis.line =element_blank())
  43. ```
  44. ### Réseaux
  45. ```{r}
  46. nodes <- data.frame(id = glue::glue("node{1:11}"),
  47. #label = c("node1","node2","node3"),
  48. node_type= rep(1,11))
  49. edges <- data.frame(from = c("node1","node1","node1","node1","node1", "node5", "node5", "node5", "node6", "node9","node9"),
  50. to = c("node2","node3", "node4", "node5","node6", "node7", "node8", "node9", "node9", "node10", "node11"),
  51. type = rep("normal",11) ,
  52. weight = rep(1,11))
  53. net <- graph_from_data_frame(d=edges, vertices = nodes, directed = FALSE)
  54. ggraph(net) +
  55. geom_edge_link(end_cap = circle(0, 'mm'),
  56. start_cap = circle(0, 'mm'), edge_width = 1) +
  57. geom_node_point(color = 'darkred', fill ="darkred", size = 10, shape = 21) +
  58. expand_limits(y=c(-1.5,1.5), x = c(-1.5,1.5)) +
  59. annotate("curve", x=1.2,xend=1.3,y=-.6,yend=-.3,curvature=.2, arrow=arrow(type="closed",length= unit(.4,"cm"))) +
  60. annotate("text", x=1.2, y=-.6, label = "Noeud (Node)",hjust=0.5, vjust=1) +
  61. annotate("curve", x=.4,xend=.5,y=1,yend=.5,curvature=-0.2, arrow=arrow(type="closed",length= unit(.4,"cm"))) +
  62. annotate("text", x=.4, y=1, label = "Lien (Edge)",hjust=0.5, vjust=-.7) +
  63. theme_void_complete()
  64. ```
  65. ### TODO: Champs
  66. ```{r}
  67. make_grid_data <- function(size) {
  68. data.frame(x = c(rep(1,size), 1:size),
  69. xend = c(rep(size,size), 1:size),
  70. y = c(1:size, rep(1,size)),
  71. yend = c(1:size, rep(size,size)))
  72. }
  73. size = 8
  74. p1 <- ggplot(make_grid_data(size)) +
  75. geom_segment(aes(x=x, xend=xend, y=y, yend=yend)) +
  76. geom_rect(xmin = 2, xmax=3, ymin=6, ymax=7, fill="darkred") +
  77. annotate("text", x=4.5,y = 10, label= "Grille de positions", size =6)+
  78. xlim(c(1,size*2-1))+
  79. ylim(c(-5,size+2))+
  80. coord_polar(start = -pi/2) +
  81. theme_void_complete() +
  82. theme(plot.margin=unit(c(0,0,0,0),"lines"),
  83. panel.spacing=unit(0,"lines"),
  84. axis.ticks.margin=unit(0,"cm"))
  85. p2<- ggplot(data = make_tabular_data(5,1,3),
  86. mapping = aes(x = x, y = y, fill = as.factor(group))) +
  87. geom_tile(color = 'white', size = 2) +
  88. annotate("segment", x=.7,xend=5.5,y=1.6,yend=1.6,arrow=arrow(type="closed",length= unit(.4,"cm"))) +
  89. #annotate("segment", x=0.2,xend=0.2,y=3.8,yend=1,arrow=arrow(type="closed",length= unit(.4,"cm"))) +
  90. annotate("text", x=3, y=0, label = "Valeur dans une cellule",hjust=0.5, vjust=1) +
  91. annotate("text", x=3, y=1.6, label = "Attributs (colonnes)",hjust=0.5, vjust=-1) +
  92. annotate("segment", x=3,xend=3,y=0,yend=0.5,arrow=arrow(type="closed", length= unit(.4,"cm"))) +
  93. scale_fill_manual(values = list("lightgrey", "darkred"))+
  94. scale_x_continuous(position = "top")+
  95. ylim(-1, 2) +
  96. theme_void_complete()
  97. (plot_spacer() | p1 | plot_spacer()) / (plot_spacer() | p2 | plot_spacer())
  98. ```
  99. ### TODO: Spacial
  100. ## Types de données
  101. ### TODO