ropensci / visdat

Preliminary Exploratory Visualisation of Data
https://docs.ropensci.org/visdat/
Other
450 stars 47 forks source link

vis_value - visualise each column on a 0-1 scale #100

Closed njtierney closed 5 years ago

njtierney commented 5 years ago

This could look something like the following:

library(magrittr)
vis_value <- function(data, na_colour = "grey90") {
  scale_01 <- function(x) {
    (x - min(x, na.rm = TRUE)) / diff(range(x, na.rm = TRUE))
  }

  purrr::map_dfr(data, scale_01) %>%
    visdat:::vis_gather_() %>%
    dplyr::mutate(value = visdat:::vis_extract_value_(data)) %>%
    visdat:::vis_create_() +
    # change the limits etc.
    ggplot2::guides(fill = ggplot2::guide_legend(title = "Value")) +
    # add info about the axes
    ggplot2::scale_x_discrete(position = "top") +
    ggplot2::theme(axis.text.x = ggplot2::element_text(hjust = 0)) +
    ggplot2::scale_fill_viridis_c(option = "D",
                                  na.value = na_colour)

}

vis_value(airquality)

Created on 2018-11-04 by the reprex package (v0.2.1)

njtierney commented 5 years ago

closes #92

vis_value is now in the vis-value branch

njtierney commented 5 years ago

Here is some example code to animate through arranging each of the columns

library(magick)
library(tidyverse)
library(visdat)

d1 <- airquality %>% arrange(Day)
d2 <- airquality %>% arrange(Month)
d3 <- airquality %>% arrange(Ozone)
d4 <- airquality %>% arrange(Solar.R)
d5 <- airquality %>% arrange(Temp)
d6 <- airquality %>% arrange(Wind)

df_list <- list(d1, d2, d3, d4, d5, d6)

print_vis <- map(df_list, vis_value)

print_vis

img <- image_graph(600, 340, res = 96)
print_vis
dev.off()
animation <- image_animate(img, fps = 1)
print(animation)