Guest User

Untitled

a guest
Jul 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. library(dplyr)
  2. library(ggplot2)
  3. library(purrr)
  4. library(colormap)
  5. library(gridExtra)
  6. library(gghighlight)
  7.  
  8. df <-
  9. 1:2 %>%
  10. map(~ invoke(data_frame,
  11. label = letters[1:10],
  12. value = rnorm(length(letters[1:10]),
  13. mean = 10)) %>%
  14. arrange(desc(value)) %>%
  15. mutate(rank = row_number()))
  16.  
  17. p_1 <-
  18. ggplot(df[[1]],
  19. aes(rank, value, fill = label)) +
  20. geom_bar(stat = "identity", width = 1, color = "white") +
  21. geom_text(aes(y = -1, label = label, color = label), size = 10, fontface = "bold") +
  22. coord_flip() +
  23. scale_color_colormap(colormap = colormaps$warm, discrete = TRUE) +
  24. scale_fill_colormap("label", colormap = colormaps$warm, discrete = TRUE) +
  25. scale_x_reverse() +
  26. scale_y_reverse() +
  27. theme_void() +
  28. theme(panel.background = element_rect(fill = "#D0CCC0",
  29. color = "#D0CCC0")) +
  30. guides(fill = FALSE, color = FALSE)
  31.  
  32. p_2 <-
  33. ggplot(df[[2]],
  34. aes(rank, value, fill = label)) +
  35. geom_bar(stat = "identity", width = 1, color = "white") +
  36. geom_text(aes(y = -1, label = label, color = label), size = 10, fontface = "bold") +
  37. coord_flip() +
  38. scale_color_colormap(colormap = colormaps$warm, discrete = TRUE) +
  39. scale_fill_colormap("label", colormap = colormaps$warm, discrete = TRUE) +
  40. scale_x_reverse() +
  41. theme_void() +
  42. theme(panel.background = element_rect(fill = "#D0CCC0",
  43. color = "#D0CCC0")) +
  44. guides(fill = FALSE, color = FALSE)
  45.  
  46. df_rank <-
  47. df[[1]] %>%
  48. mutate(x = 1) %>%
  49. bind_rows(
  50. df[[2]] %>%
  51. mutate(x = 2)) %>%
  52. select(-value) %>%
  53. rename(letter = label)
  54.  
  55. p_tangle <-
  56. ggplot(df_rank,
  57. aes(x = x, y = rank, col = letter)) +
  58. geom_line(size = 1.5) +
  59. scale_color_colormap("label", colormap = colormaps$warm, discrete = TRUE) +
  60. theme_void() +
  61. scale_y_reverse(limits = c(11, 0)) +
  62. theme(panel.background = element_rect(fill = "#D0CCC0",
  63. color = "#D0CCC0")) +
  64. guides(color = FALSE)
  65.  
  66. p_out <-
  67. grid.arrange(p_1,
  68. p_tangle,
  69. p_2,
  70. widths= c(0.4, 0.2, 0.4),
  71. ncol = 3)
  72.  
  73. grid.arrange(p_1,
  74. p_tangle + gghighlight(letter %in% c("a", "j"),
  75. use_group_by = FALSE,
  76. use_direct_label = FALSE),
  77. p_2,
  78. widths= c(0.4, 0.2, 0.4),
  79. ncol = 3)
Add Comment
Please, Sign In to add comment