This is an example of creating what could be a legend for a heat map, demonstrating the simple use of a data-driven linear gradient with D3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## reproduce the figures from http://www.jstatsoft.org/v28/c01/paper using ggplot2 | |
library(ggplot2) | |
## parameters | |
set.seed(2710) | |
## Figure 1 | |
d <- rnorm(50) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This second example runs Trueskill on a tennis tournament, the Australian Open. | |
# Note that actual computation is commented out as it takes about ~40 seconds to | |
# update skill ratings over 127 matches. | |
library(trueskill) | |
# Data format of ausopen2012 is: Player, Opponent, Margin, Round, WRank, LRank | |
data("ausopen2012") | |
# create match_id in order to reshape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(tidyr) | |
library(magrittr) | |
library(ggplot2) | |
"http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYNEWYOR.txt" %>% | |
read.table() %>% data.frame %>% tbl_df -> data | |
names(data) <- c("month", "day", "year", "temp") | |
data %>% | |
group_by(year, month) %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
library(htmltools) | |
library(pipeR) | |
library("DiagrammeR") | |
html(' | |
<ul class="ze_imagelist" style="width:925px;height:400px;" id="slideshowpj_widget_54da647bbdf7e"><li class="ze_thumb ze_type_image ze_item_number_1"><a class="ze_box" rel="prettyPhoto[pj_widget_54da647bbdf7e]" href="http://ec12.cdn.cincopa.com/SaltedCaramel2.jpg?o=1&res=76&cdn=ec&p=y&pid=231720&ph3=b2d1timslim1sat2p2lxtiganpc1chim&d=AMWAjFwULOAANQJsAMnyJRB&as=mp3" title="Salted Caramel - Our Signature Cookie<br />Our Signature Cookie! Caramel-infused dough loaded with Chocolate Chips and drizzled with Salted Caramel Sauce" style="width:190px;height:190px;"> <div class="ze_overlay"></div> <div id="pj_widget_54da647bbdf7e_0_thumbsplash" class="ze_item" style="width:190px;height:190px;"> <img class="ze_postar" style="height:190px;" src="http://ec12.cdn.cincopa.com/SaltedCaramel2.jpg?o=1&res=76&cdn=ec&p=y&pid=231720&ph3=b2d1timslim1sat2p2lxtiganpc1chim&d=AMWAjFwULOAANQJsAMnyJRB" t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
body{ | |
margin: 0px; | |
font: 10px sans-serif; | |
} | |
path.player{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viridis_pal <- function(alpha=1) { | |
function(n) { | |
viridis(n, alpha) | |
} | |
} | |
scale_color_viridis <- function(..., alpha=1, discrete=TRUE) { | |
if (discrete) { | |
discrete_scale("colour", "viridis", viridis_pal(alpha), ...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' NBA Player Shot Chart | |
#' | |
#' @param player name the player, must be exact | |
#' @param author, year_end_season: numeric end of season | |
#' | |
#' @return | |
#' @export | |
#' | |
#' @examples boggie_bog <- plot_player_shot_chart(player = "Bojan Bogdanovic", | |
#year_season_end = 2015, exclude_backcourt = T |
@jalapic did these really nice set of touch heatmap charts. On Twitter, there was a discussion how to do this interactively with d3.js or some other JavaScript. I definitely have some ideas how to accomplish this, but for now let's see how we can kind of do it in rbokeh
. There is just a small issue with palette selection in Bokeh that does not let us allow a no color that prevents us from getting really close.
## https://gist.github.com/jalapic/3616c0197ece24060e99
library(rbokeh)
library(dplyr)
gana <- read.csv("https://gist.githubusercontent.com/jalapic/3616c0197ece24060e99/raw/2bc2361c5fceb9be80dece9b7ffa14d129a3edfb/gana.csv")
figure() %>%
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(FField) | |
# You'll have to play with repulsion, cex.x, and cex.y to get satisfactory results. | |
plot_text <- function(x, y, label, repulsion = 1, cex.x = 110, cex.y = 40) { | |
dat <- data.frame(xpos = x, ypos = y, label = label) | |
dat$label <- as.character(dat$label) | |
# Use the FField package to repel the text labels away from each other. | |
dat <- cbind( |
OlderNewer