Week45 - shotsignR
November 13, 2015
Some Love for queryBuildR
Somehow I missed queryBuildR
when it was released. I strongly recommend checking it out.
This Week’s Widget - shotsignR
Peter Beshai created beautiful d3.js
Shooting Signatures to visualize basketball shooting performance. It was definitely love at first sight for me. However, to justify spending time creating an htmlwidget
, I needed some inspiration and also a non-basketball use case. Both the inspiration and use case came from a reader.
Unfortunately, this is still very much a work-in-progress. I’m hoping for some additional inspiration/help to finish it up. Also, midway through this project, I realized that this is sort-of a modified streamgraph
, so I might circle back to see if I can build on top of Bob Rudis’ excellent streamgraph package.
Installation
This is not on CRAN, so to install we will need some help from devtools::install_github
.
devtools::install_github("timelyportfolio/shotsignR")
Examples
Basketball Example
# devtools::install_github("timelyportfolio/shotsignR")
library("shotsignR")
# use data from Peter Beshai gist https://gist.github.com/pbeshai/ffd0f9d84b4e8df27db2
test_data <- jsonlite::fromJSON(
paste0(
'https://gist.githubusercontent.com/',
'timelyportfolio/d00488979c22fc4ed900/raw/',
'a7838e5ea1abe9f0d836e55499bd618efaeae5b7/shotsign.json'
)
)
shotsign( test_data )
Non-basketball Usage
# devtools::install_github("timelyportfolio/shotsignR")
library("shotsignR")
# now let's try the example from @kferris10
library(dplyr)
library(magrittr)
library(ggplot2)
x <- read.table("http://www.stat.ufl.edu/~winner/data/ecophys_rc.dat") %>%
setNames(c("location", "treatment", "plant_id", "co2_concentration", "co2_uptake_rate")) %>%
group_by(plant_id) %>%
mutate(time = 1:n()) %>%
ungroup()
x %>%
filter(plant_id == 1) %>%
qplot(time, co2_uptake_rate, data = ., geom = "line", group = plant_id,
colour = co2_concentration, size = co2_concentration)
x %>%
filter(plant_id == 1) %>%
select(time, co2_uptake_rate, co2_concentration, co2_concentration) %>%
set_colnames(c("x","y","widthValue")) %>%
mutate(colorValue = widthValue/max(widthValue)) %>%
{
shotsign(
.,
xdomain = range(.$x),
ydomain = range(.$y),
wdomain = range(.$w),
colordomain = c(0,1)
)
}
Thanks
Thanks Peter Beshai for Shooting Signatures.
As always, thanks to
- Ramnath Vaidyanathan and RStudio for
htmlwidgets
- all the contributors to
R
andJavaScript