Skip to content

Instantly share code, notes, and snippets.

@shenqi
shenqi / draw_ggplot.R
Last active August 29, 2015 14:01
Pre-defined formats for ggplot
library(ggplot2)
require(ggplot2)
# also require ggplot_lm.R on https://gist.github.com/shenqi/29b42a6be83ec9e0517d
ggplot0 <- function(x, y, data, label, shape, ...){
return(ggplot(data, aes_string(x = x, y = y, label = label, shape = shape, ...)))
}
draw_ggplot <- function(x, y, data, point.size, label, label.hjust, shape, shape.solid, lm_formula, r2.adjusted, r2.pos_x, r2.pos_y, r2.digits, r2.color, legend.position, ...) {
g0 <- ggplot0(x, y, data, label, shape, ...) + geom_point(size = I(point.size)) + theme_classic()
@shenqi
shenqi / tidy_plot.R
Last active August 29, 2015 14:01
Tidy and combine ggplot
library(gtable)
require(gtable)
library(foreach)
require(foreach)
unit.def <- 'inches'
plot.length.def <- 6
legend.length.def <- 1.5
as.unit <- function(n){return(unit(n, unit.def))}
@shenqi
shenqi / risona.R
Created August 13, 2014 09:22
りそなダイレクトからダウンロードできる入出金明細データとVISAデビットデータを組み合わせて見やすいCSVファイルを出力する
library(stringr)
# 出入金レコード
b <- read.csv('bank statement.csv', fileEncoding='cp932')
b$date <- paste0(b$取扱日付.年,'/',b$取扱日付.月,'/',b$取扱日付.日)
b$amount <- ifelse(b$取引名 == '入金', b$金額, -b$金額)
b$detail <- ifelse(str_detect(b$摘要, 'VISA'), str_sub(b$摘要, 11, 16), as.character(b$摘要))
b$payee <- ifelse(str_detect(b$摘要, 'VISA'), '', as.character(b$摘要))
# b[,22:25]