Week30 - taucharts
August 05, 2015
This Week’s Widget - taucharts
As I said in week 1, an htmlwidget
collaboration still qualifies as an htmlwidget
of the week. This week’s taucharts
is a very fine case of why I set this rule. boB Rudis @hrbrmstr delighted me when he started to tackle the very well-designed TauCharts
. Check out the TauCharts
site, docs, and design post, and I think you’ll quickly see why we have both been very intrigued by this library. Bob’s first tweet said
“now to find the time to finish it :-)”
I took this as an invitation to participate and quickly responded especially since I had hesitated on TauCharts
becuase I didn’t think I would have the time in a week to cover all of its features. Please note almost all the code and credit for taucharts
belongs to Bob. I simply chipped in where possible.
Quick Installation
taucharts
is not yet on CRAN, so for now please install with devtools::install_github
.
devtools::install_github("hrbrmstr/taucharts")
Examples
@hrbrmstr has already assembled quite a few examples in the documentation, this RPubs, and his blog post Achieve Charting Zen With TauCharts. I’ll try to supplement instead of replicate his examples. Limiting myself to only a couple of examples with so much functionality will be tricky.
I very often go to the Deepayan Sarkar’s (author of lattice
) book Lattice: Multivariate Data Visualization with R (Use R!) to find examples to replicate with new charting libraries. Let’s look at a couple of my favorites starting with bars since these can be quite tricky. As an aside, xtabs
still just does not get nearly the credit it deserves.
Stacked Bar
# devtools::install_github("hrbrmstr/taucharts")
library(taucharts)
# http://lmdvr.r-forge.r-project.org/figures/figures.html
xtabs( Freq ~ Survived + Sex, Titanic ) %>%
# tables get automatically converted to a data.frame
tauchart() %>%
tau_stacked_bar( "Sex", "Freq", "Survived" ) %>%
tau_guide_y( label = "# of Passengers") %>%
tau_legend()
Facets/Strips
R
users need facets
/strips
, and taucharts
makes it easy.
# devtools::install_github("hrbrmstr/taucharts")
library(taucharts)
# based off http://lmdvr.r-forge.r-project.org/figures/figures.html
Titanic %>%
# tables get automatically converted to a data.frame
tauchart() %>%
tau_bar(
c( "Age","Sex" )
, c( "Class", "Freq" )
, "Survived"
) %>%
tau_legend()
Facetted Line
library(taucharts)
# based off http://lmdvr.r-forge.r-project.org/figures/figures.html
## Figure 2.1
data(Oats, package = "MEMSS")
# xyplot(yield ~ nitro | Variety + Block, data = Oats, type = 'o')
tauchart( Oats ) %>%
tau_line( "Block", c("Variety", "yield") , "nitro" ) %>%
tau_tooltip() %>%
tau_legend()
Tricky R->JS Dates
Date handling from R
to JavaScript
can get tricky quickly. Although date support is not as full featured as I would like, taucharts
does pretty well with dates.
library(taucharts)
library(xts)
as.xts(
data.frame( "random" = runif( 100, 0, 100 ) )
, order.by = seq(Sys.Date(),Sys.Date()+99,by="days")
) %>%
tauchart() %>%
# xts index get added as a column named Date
tau_point( "Date", "random" ) %>%
tau_guide_x( tick_format = "%b %d" )
Trendlines
R
can draw some mean trendlines, but can JavaScript
?
library(taucharts)
CO2 %>%
tauchart( ) %>%
tau_point( "conc", c("Treatment","uptake"), "Plant" ) %>%
tau_tooltip( ) %>%
tau_trendline( )
This is certainly not all, but I’ll stop here. As always, feedback, examples, use cases are very welcome.
Thanks
Thanks so much to boB Rudis for a really wonderful collaborative experience fueled by his vast wealth of skill and experience. Thanks to Petriko Vladimir at targetprocess for the spectacular charting library TauCharts
.
As always, thanks to
- Ramnath Vaidyanathan and RStudio for
htmlwidgets
- all the contributors to
R
andJavaScript