Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(dplyr)
- library(ggplot2)
- library(purrr)
- library(colormap)
- library(gridExtra)
- library(gghighlight)
- df <-
- 1:2 %>%
- map(~ invoke(data_frame,
- label = letters[1:10],
- value = rnorm(length(letters[1:10]),
- mean = 10)) %>%
- arrange(desc(value)) %>%
- mutate(rank = row_number()))
- p_1 <-
- ggplot(df[[1]],
- aes(rank, value, fill = label)) +
- geom_bar(stat = "identity", width = 1, color = "white") +
- geom_text(aes(y = -1, label = label, color = label), size = 10, fontface = "bold") +
- coord_flip() +
- scale_color_colormap(colormap = colormaps$warm, discrete = TRUE) +
- scale_fill_colormap("label", colormap = colormaps$warm, discrete = TRUE) +
- scale_x_reverse() +
- scale_y_reverse() +
- theme_void() +
- theme(panel.background = element_rect(fill = "#D0CCC0",
- color = "#D0CCC0")) +
- guides(fill = FALSE, color = FALSE)
- p_2 <-
- ggplot(df[[2]],
- aes(rank, value, fill = label)) +
- geom_bar(stat = "identity", width = 1, color = "white") +
- geom_text(aes(y = -1, label = label, color = label), size = 10, fontface = "bold") +
- coord_flip() +
- scale_color_colormap(colormap = colormaps$warm, discrete = TRUE) +
- scale_fill_colormap("label", colormap = colormaps$warm, discrete = TRUE) +
- scale_x_reverse() +
- theme_void() +
- theme(panel.background = element_rect(fill = "#D0CCC0",
- color = "#D0CCC0")) +
- guides(fill = FALSE, color = FALSE)
- df_rank <-
- df[[1]] %>%
- mutate(x = 1) %>%
- bind_rows(
- df[[2]] %>%
- mutate(x = 2)) %>%
- select(-value) %>%
- rename(letter = label)
- p_tangle <-
- ggplot(df_rank,
- aes(x = x, y = rank, col = letter)) +
- geom_line(size = 1.5) +
- scale_color_colormap("label", colormap = colormaps$warm, discrete = TRUE) +
- theme_void() +
- scale_y_reverse(limits = c(11, 0)) +
- theme(panel.background = element_rect(fill = "#D0CCC0",
- color = "#D0CCC0")) +
- guides(color = FALSE)
- p_out <-
- grid.arrange(p_1,
- p_tangle,
- p_2,
- widths= c(0.4, 0.2, 0.4),
- ncol = 3)
- grid.arrange(p_1,
- p_tangle + gghighlight(letter %in% c("a", "j"),
- use_group_by = FALSE,
- use_direct_label = FALSE),
- p_2,
- widths= c(0.4, 0.2, 0.4),
- ncol = 3)
Add Comment
Please, Sign In to add comment