Skip to content

Instantly share code, notes, and snippets.

View kohske's full-sized avatar

kohske takahashi kohske

  • Ritsumeikan University
  • Osaka, Japan
  • X @kohske
View GitHub Profile
@kohske
kohske / knitr_demo.Rmd
Created July 12, 2012 08:01
knitr demo
```{r setup}
library(xtable)
library(ggplot2)
library(gridExtra)
options(xtable.type = "html")
```
```{r table1, results='asis'}
xtable(head(iris))
@kohske
kohske / statsummary.R
Last active December 11, 2015 09:18
Temporary patch for stat_summary with geom_line
library(ggplot2)
library(proto)
StatSummary <- proto(ggplot2:::Stat, {
objname <- "summary"
default_geom <- function(.) GeomPointrange
required_aes <- c("x", "y")
calculate_groups <- function(., data, scales, fun.data = NULL, fun.y = NULL, fun.ymax = NULL, fun.ymin = NULL, na.rm = FALSE, ...) {
data <- remove_missing(data, na.rm, c("x", "y"), name = "stat_summary")
if (!missing(fun.data)) {
fun.data <- match.fun(fun.data)
library(XML)
# 負荷軽減のため
if (length(dir(".", "^data.Rda$")) == 0) {
data <- xmlToDataFrame("http://www3.city.sabae.fukui.jp/xml/population/population.xml",
stringsAsFactors=FALSE,
colClasses=c("integer","integer","character",
"numeric","numeric","numeric",
"numeric","character"))
save("data", file = "data.Rda")
@kohske
kohske / index.html
Created July 5, 2013 08:50
Scatterplot
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://polychart.com/s/third_party/polychart2.standalone.js' type='text/javascript'></script>
<style>
.rChart {
display: block;
@kohske
kohske / whcor.R
Created August 28, 2013 04:28
ggplot2 visualization with xkcd style. Output: https://twitter.com/kohske/status/372575134806077440/photo/1
h <- rnorm(1000, 160, 10)
w <- rnorm(1000, 0, 10)/(pmin(abs(h-160), 1)) + (h-60)*0.75
d <- data.frame(x=w, y=h)
p <- ggplot(data=d, aes(x=x,y=y)) + geom_point(colour = "gray50", alpha=0.5, size = 5)
mapping <- aes(x=x,
y=y,
scale=scale,
ratioxy=ratioxy,
angleofspine = angleofspine,
@kohske
kohske / gvis.Rpres
Last active December 31, 2015 02:49
Rstudio + Rpres + googleVisのマークダウンファイル。簡単ですね。
Rstudio + Rpres + googleVis
========================================================
author: @kohske
date: 2013/12/12
とりあえずプロット
========================================================
```{r, echo=FALSE, results='asis', warning=FALSE, message=FALSE}
library(googleVis)
@kohske
kohske / index.Rmd
Created January 17, 2014 08:49
slidify-minimal
---
title : はじめてのslidify
subtitle : マークダウンで楽々HTML5スライド作成
author : "@kohske"
job :
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : standalone # {selfcontained, standalone, draft}
@kohske
kohske / sample.Rnw
Last active August 29, 2015 13:56
knitr+animation+latex
\documentclass{ltjsarticle}
\usepackage{luatexja}
\let\ifdraft\relax % おまじない
\usepackage{animate}
\title{PDFレポートでアニメーション}
\author{@kohske}
\begin{document}
\maketitle
@kohske
kohske / lp.R
Last active August 29, 2015 13:56
「R & knitr で文芸的プログラミング的な何か」のWEBファイル
## ----include=FALSE-------------------------------------------------------
library(knitr)
opts_chunk$set(tidy=TRUE)
## ----平均しますね--------------------------------------------------------------
Mean <- function(x) {
y <-
@kohske
kohske / rmarkdown-to-html
Created February 21, 2014 03:02
emacsでknit2html
(defun rmarkdown-to-html ()
"Run knitr::knit2html on the current file"
(interactive)
(shell-command
(format "Rscript -e \"knitr::knit2html('%s')\""
(shell-quote-argument (buffer-file-name)))))