Bläddra i källkod

Tweak spread + gather

pull/22/head
Kirill Müller 7 år sedan
förälder
incheckning
c42a32c58c
7 ändrade filer med 161 tillägg och 160 borttagningar
  1. +2
    -1
      R/02_functions.R
  2. +5
    -5
      R/tidyr_spread_gather.R
  3. Binär
      images/static/png/tidyr-gather.png
  4. Binär
      images/static/png/tidyr-spread.png
  5. +83
    -83
      images/static/svg/tidyr-gather.svg
  6. +71
    -71
      images/static/svg/tidyr-spread.svg
  7. Binär
      images/tidyr-spread-gather.gif

+ 2
- 1
R/02_functions.R Visa fil

@@ -65,7 +65,8 @@ colorize_wide_tidyr <- function(df, n_colors, key_col = "id") {
color = colors[idc],
) %>%
filter(!is.na(color)) %>%
mutate(alpha = ifelse(label != "id" & .y < 0, 0.6, 1.0)) %>%
mutate(alpha = ifelse(.y < 0, 1.0, 0.2)) %>%
mutate(.text_color = ifelse(.y < 0, "white", "black")) %>%
select(-idc)
}


+ 5
- 5
R/tidyr_spread_gather.R Visa fil

@@ -7,6 +7,7 @@ sg_wide <- wide %>%
sg_long <- wide %>%
tidyr::gather("key", "val", -id) %>%
proc_data("3-tall", color_fun = function(x, y) x) %>%
mutate(.text_color = if_else(label == "key", "black", "white")) %>%
split(.$label)

sg_long$id <-
@@ -22,26 +23,26 @@ sg_long$key <-
select(label, color) %>%
left_join(sg_long$key, ., by = c("value" = "label")) %>%
distinct() %>%
mutate(alpha = 1)
mutate(alpha = 0.6)

sg_long$val <-
sg_wide %>%
filter(label != "id", .y < 0) %>%
select(value, color) %>%
left_join(sg_long$val, ., by = "value") %>%
mutate(alpha = 0.6)
mutate(alpha = 1)

sg_long <- bind_rows(sg_long) %>% mutate(frame = 2)

sg_long_labels <- data_frame(id = 1, a = "id", x = "key", y = "val") %>%
proc_data("4-label") %>%
filter(label != "id") %>%
mutate(color = "#FFFFFF", .y = 0, .x = .x -1, frame = 2, alpha = 1, label = recode(label, "a" = "id"))
mutate(color = "white", .text_color = "black", .y = 0, .x = .x -1, frame = 2, alpha = 1, label = recode(label, "a" = "id"))

sg_wide_labels <- data_frame(id = 1, a = "id") %>%
proc_data("2-label") %>%
filter(label != "id") %>%
mutate(color = "#FFFFFF", .y = 0, .x = .x -1, frame = 1, alpha = 1, label = recode(label, "a" = "id"))
mutate(color = "white", .text_color = "black", .y = 0, .x = .x -1, frame = 1, alpha = 1, label = recode(label, "a" = "id"))

sg_long_extra_keys <- map_dfr(
seq_len(nrow(wide) - 1),
@@ -66,7 +67,6 @@ sg_data <- bind_rows(
mutate(
label = ifelse(value %in% setdiff(colnames(wide), "id"), "key", label),
label = ifelse(value %in% c("key", "val"), "zzz", label),
.text_color = ifelse(grepl("label", .id), "black", "white"),
.text_size = ifelse(grepl("label", .id), 8, 12)
) %>%
arrange(label, .id, value) %>%

Binär
images/static/png/tidyr-gather.png Visa fil

Before After
Width: 3429  |  Height: 4658  |  Size: 373KB Width: 1999  |  Height: 1999  |  Size: 40KB

Binär
images/static/png/tidyr-spread.png Visa fil

Before After
Width: 3429  |  Height: 4658  |  Size: 347KB Width: 1999  |  Height: 1999  |  Size: 32KB

+ 83
- 83
images/static/svg/tidyr-gather.svg
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 71
- 71
images/static/svg/tidyr-spread.svg
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


Binär
images/tidyr-spread-gather.gif Visa fil

Before After
Width: 480  |  Height: 480  |  Size: 789KB Width: 480  |  Height: 480  |  Size: 904KB

Laddar…
Avbryt
Spara