R/wordfeudplots.R

load("/Users/ling-jwe/Documents/R/PACKAGES/games/data/mygames.RData")

vowels=c("a","e","i","o","u")
blank="?"
wf$mytiles=wf$used;wf$mytiles[wf$used==""]=wf[wf$used=="","unused"]

# boxplot of points by turn
ggplot(wf,aes(x=factor(turn),y=points,col=turn))+geom_boxplot(varwidth=TRUE)

# Relation between number of tiles and score
# The more tiles you use, the higher the score
ggplot(data.frame(x=tapply(nchar(wf$used),wf$start,sum),
                  y=tapply(wf$points,wf$start,sum)),
                  aes(x=x,y=y,col=y)) + geom_point() +xlab("Number of tiles") + ylab("Total score") + 
   geom_vline(aes(xintercept=52))

# Relation between number of turns and score
# The more turns, the lower the score (painstaking game)
ggplot(data.frame(y=tapply(wf$points,wf$start,sum),
   x=factor(table(wf$start))),aes(x=x,y=y))+geom_boxplot() + 
   xlab("Number of turns") + ylab("Total score")

# How many tiles used per turn
ggplot(wf,aes(nchar(used),fill="tomato3",col="black")) + geom_bar(show.legend=FALSE) + 
   xlab("Tiles used per turn") + ylab("Count")

# How many turns per game
ggplot(data.frame(table(wf$start)),aes(Freq,fill="tomato3",col="black")) + geom_bar(show.legend=FALSE) + 
   xlab("Turns per game") + ylab("Count")

# How many tiles used and the number of vowels
tiles.list=sapply(wf$mytiles,function(tiles){strsplit(tiles,split="")})
wf$vowels=sapply(tiles.list,function(x){sum(x%in%vowels)})
ggplot(data.frame(x=tapply(wf$vowels,wf$start,sum),
                  y=tapply(nchar(wf$mytiles),wf$start,sum)),
                  aes(x=x,y=y,col=y)) + geom_point() + 
   xlab("Number of vowels (out of 39)") + ylab("Tile count") 

# Average score on 0, 1 or 2 blanks
tiles.list=sapply(wf$mytiles,function(tiles){strsplit(tiles,split="")})
wf$blank=sapply(tiles.list,function(x){sum(x%in%blank)})
ggplot(with(wf,aggregate(list(blank=blank,points=points),by=list(start=start),sum)),
   aes(x=factor(blank),y=points))+geom_boxplot()
vdweijer/games documentation built on Dec. 23, 2021, 3:02 p.m.