Skip to content

Instantly share code, notes, and snippets.

@kohske
Created March 25, 2012 17:14
Show Gist options
  • Select an option

  • Save kohske/2198387 to your computer and use it in GitHub Desktop.

Select an option

Save kohske/2198387 to your computer and use it in GitHub Desktop.
sazae san no janken
d <- iconv(readLines("http://www.asahi-net.or.jp/~tk7m-ari/sazae_ichiran.html"), "sjis")
d <- strsplit(gsub("<BR>$", "", d[grepl("^第[0-9]+回", d)]), "\t")
d <- as.data.frame(do.call("rbind", d), stringsAsFactors = FALSE)
names(d) <- c("N", "D", "H")
d[d$N=="第7回", ]$D <- "91.12.01"
d <- transform(d,
N = gsub("[^0-9]", "", N),
D = as.Date(D, "%y.%m.%d"),
H = ifelse(grepl("グー", H), "グー",
ifelse(grepl("チョキ", H), "チョキ",
ifelse(grepl("パー", H), "パー",
"休み")))
)
theme_set(theme_grey(base_family = "sans"))
# 頻度
p1 <- ggplot(d, aes(H)) + geom_bar() + labs(x = NULL, y = "頻度")
# 頻度(月毎)
p2 <- ggplot(d, aes(months(d$D, T), colour = H)) +
stat_bin(aes(group = H), geom = c("line"), position = "identity") +
labs(x = "月", y = "頻度")
# 前週との関係
d3 <- data.frame(embed(d$H, 2))
p3 <- ggplot(d2, aes(X1, X2)) + stat_bin2d(aes(size = ..count..), geom = "point") +
labs(x = "前の週", y = "今週")
p4 <- ggplot(d2, aes(X1, fill = X2)) + geom_bar(position = "fill") +
labs(x = "前の週", fill = "今週", y = "確率")
library(gridExtra)
grid.arrange(p1, p2, p3, p4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment