experiment/diamonds.R

library(ggplot2)
library(tabplot)
library(RJSONIO)

data(diamonds)

# adjustment of tableplot object, to be implemented in tabplot itself
adjust <- function(tp){
  atp <- list()
  varnms <- sapply(tp$columns, function(i) i$name)
  vars <- lapply( tp$columns
                , function(i) { if (i$isnumeric)
                                return(list( mean = i$mean
                                           , compl = i$compl/100
                                           )
                                      )
                                categories <- colnames(i$freq)
                                freq <- round(i$freq / rowSums(i$freq), 4)
                                colnames(freq) <- NULL
                                list( freq = freq, palet=i$palet, categories=categories)
                                
                  }
                )
  names(vars) <- varnms
  atp$vars <- vars
  atp
}

tp <- tableplot(diamonds[c("carat", "price", "cut")], plot=FALSE)
atp <- adjust(tp)
writeLines(toJSON(atp), con="diamonds.json")
toJSON
edwindj/tabplotd3 documentation built on May 15, 2019, 11:06 p.m.