Skip to content

Instantly share code, notes, and snippets.

@gghatano
gghatano / gist:8502924
Created January 19, 2014 10:23
for makky2
library(ggplot2)
# make dataframe
x <- seq(0,3, by = 0.1)
y <- x^2
xy <- data.frame(x = x, y = y)
# plot
p <- ggplot()
p <- p + geom_line(data = xy, aes(x = x, y = y))
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import urllib
from BeautifulSoup import BeautifulSoup
html = '''
上記HTML。ここに書くと表示が乱れるので分けました。
'''
@gghatano
gghatano / fastballcount.R
Created January 25, 2014 16:03
fastball count (2013)
library(pitchRx)
library(ggplot2)
library(data.table)
library(dplyr)
# データ取得
# data = scrapeFX("2013-01-01", "2013-10-01")
# 取得済みデータの利用
# data <- fread("2013.csv")
@gghatano
gghatano / babip_pitcher.R
Created February 9, 2014 05:10
babip (pitcher)
library(data.table)
library(plyr)
library(dplyr)
master = fread("Master.csv")
master$fullname = with(master, paste(nameFirst, nameLast))
name_id_data = with(master, data.frame(name = fullname, PIT_ID = retroID))
season_babip <- function(year){
filename = paste("all", year, ".csv", sep="")
@gghatano
gghatano / pawapuro.R
Created February 11, 2014 15:41
pawapuro batting test score
library(data.table)
library(dplyr)
library(stringr)
# read data
dat = fread("all2013.csv")
fields = fread("fields.csv")
setnames(dat, fields$Header)
# processing datatable
@gghatano
gghatano / monte.r
Created March 2, 2014 15:29
montecalro with Rcpp and inline
library(Rcpp)
library(inline)
cpp_code = "
using namespace Rcpp;
double piSugar(int N){
RNGScope scope;
NumericVector x = runif(N);
NumericVector y = runif(N);
NumericVector d = sqrt(x*x + y*y);
@gghatano
gghatano / spin_rate_vs_hit_or_strike.r
Created March 6, 2014 18:51
calculate the spin_rate distribution under condition : HIT or STRIKE
library(dplyr)
library(magrittr)
library(data.table)
library(ggplot2)
# pitch f/x data 2013
dat = fread("2013.csv")
dat = dat %>% filter(sv_id !="NA")
# hit event
@gghatano
gghatano / linetype.R
Created March 12, 2014 02:15
linetype test (ggplot2)
d=data.frame(lt=c("blank", "solid", "dashed", "dotted", "dotdash", "longdash", "twodash", "1F", "F1", "4C88C488", "12345678"))
ggplot() +
scale_x_continuous(name="", limits=c(0,1), breaks=NA) +
scale_y_discrete(name="linetype") +
scale_linetype_identity() +
geom_segment(data=d, mapping=aes(x=0, xend=1, y=lt, yend=lt, linetype=lt))
@gghatano
gghatano / server.R
Last active April 10, 2016 17:03
Shiny test
library(shiny)
library(ggplot2)
library(kernlab)
library(dplyr)
library(magrittr)
shinyServer(function(input, output){
output$distPlot = reactivePlot(function(){
param = 10 ^ input$param
#package 'kernlab' = kernel pca
@gghatano
gghatano / legends.csv
Last active August 29, 2015 13:57
Visualize the records of legend batters (MLB)
playerID careerHit careerHit.x careerHit.y fullname
aaronha01 3771 3771 3771 Hank Aaron
ansonca01 3418 3418 3418 Cap Anson
biggicr01 3060 3060 3060 Craig Biggio
boggswa01 3010 3010 3010 Wade Boggs
brettge01 3154 3154 3154 George Brett
brocklo01 3023 3023 3023 Lou Brock
carewro01 3053 3053 3053 Rod Carew
clemero01 3000 3000 3000 Roberto Clemente
cobbty01 4189 4189 4189 Ty Cobb