Difference between revisions of "Talk:Ladle/Statistics"

From Armagetron
Line 1: Line 1:
=== Instructions for generating the plots for 'Individual stats' ===
+
=== Instructions for generating plots for 'Individual stats' ===
  
1. Download and install Rstudio (http://www.rstudio.com/)
+
1. Install R and Rstudio (http://cran.rstudio.com/bin/windows/base/R-3.0.2-win.exe, http://download1.rstudio.org/RStudio-0.98.501.exe)
  
2. Create a new "R script" and copy the code below (with updated ladle data)
+
2. From within Rstudio install these packages: ggplot2, Cairo
 +
 
 +
3. Create a new "R script" and copy the code below (with updated ladle data)
  
 
     require(ggplot2)
 
     require(ggplot2)
 
     require(scales)
 
     require(scales)
 +
    require(Cairo)
 
      
 
      
 
     data <- list(
 
     data <- list(
Line 25: Line 28:
 
       freako      =c(14,17,21,24,27,34,41,55,56),
 
       freako      =c(14,17,21,24,27,34,41,55,56),
 
       mazuff      =c(04,06,09,11,18,19,33,34,48),
 
       mazuff      =c(04,06,09,11,18,19,33,34,48),
 +
      vov        =c(57,65,66,69,73,74,76,78),
 
       gazelle    =c(53,62,68,69,73,74,76,77),
 
       gazelle    =c(53,62,68,69,73,74,76,77),
 
       viper      =c(07,24,27,29,30,31,36,46),
 
       viper      =c(07,24,27,29,30,31,36,46),
Line 61: Line 65:
 
                         l=unlist(data2,use.names=F),
 
                         l=unlist(data2,use.names=F),
 
                         c=unlist(sapply(data2,function(x)(1:length(x))),use.names=F),
 
                         c=unlist(sapply(data2,function(x)(1:length(x))),use.names=F),
                              m=unlist(sapply(data2,function(x)(rep(length(x),length(x)))),use.names=F))
+
                        m=unlist(sapply(data2,function(x)(rep(length(x),length(x)))),use.names=F))
 
       df2up <- df2[df2$m >= at_least,]
 
       df2up <- df2[df2$m >= at_least,]
 
       ggplot(df2up) + geom_point(aes(x=l,y=reorder(p,c),size=c,color=c),shape=21,fill="Black") +  
 
       ggplot(df2up) + geom_point(aes(x=l,y=reorder(p,c),size=c,color=c),shape=21,fill="Black") +  
Line 69: Line 73:
 
         xlab(paste("Ladle dominance (",at_least,"+) in the last ",months_ago," months since L",last_ladle,"\n", "(updated ", format(Sys.time(), "%Y/%m/%d"),")",sep=""))}
 
         xlab(paste("Ladle dominance (",at_least,"+) in the last ",months_ago," months since L",last_ladle,"\n", "(updated ", format(Sys.time(), "%Y/%m/%d"),")",sep=""))}
 
      
 
      
     ### SAVE GENERATE PLOTS
+
     ### SAVE PLOTS
     ggsave("ladle_wins.png", plot_ladle_wins(), width=14, height=7, dpi=75)
+
     ggsave("ladle_wins.png", plot_ladle_wins(), width=14, height=7, dpi=72, type="cairo-png")
     ggsave("ladle_dominance.png", plot_ladle_dominance(), width=14, height= 3.5, dpi=72)
+
     ggsave("ladle_dominance.png", plot_ladle_dominance(), width=14, height= 3.5, dpi=72, type="cairo-png")
  
 
3. Run the script. Two png plots will be saved
 
3. Run the script. Two png plots will be saved

Revision as of 04:45, 18 February 2014

Instructions for generating plots for 'Individual stats'

1. Install R and Rstudio (http://cran.rstudio.com/bin/windows/base/R-3.0.2-win.exe, http://download1.rstudio.org/RStudio-0.98.501.exe)

2. From within Rstudio install these packages: ggplot2, Cairo

3. Create a new "R script" and copy the code below (with updated ladle data)

    require(ggplot2)
    require(scales)
    require(Cairo)
    
    data <- list(
      dread       =c(22,37,39,42,48,51,54,55,56,61,65,66,69,73,74,76,78),
      fofo        =c(12,13,15,27,29,30,31,36,46,48,50,52,57,58,75),
      hoax        =c(12,13,15,22,23,28,44,45,50,55,56,61,75),
      xyron       =c(21,24,27,32,33,37,39,40,42,50,55,56,61),
      lacka       =c(03,09,11,14,18,34,35,38,43,60,63,64),
      flex        =c(12,13,15,18,19,26,29,30,31,36,50,52),
      woned       =c(16,20,25,32,37,39,40,42,53,71,72),
      eckz        =c(41,49,51,54,57,58,59,62,65,66),
      dlh         =c(06,09,18,19,33,34,35,55,56,61),
      durka       =c(08,10,14,17,22,23,28,44,45,61),
      newb        =c(01,04,06,09,11,21,24,33,34,35),
      olive       =c(21,24,27,33,38,43,55,56,61,78),
      gonzap      =c(20,32,37,39,40,42,53,71,72),
      b3er        =c(25,32,37,39,40,42,53,71,72),
      freako      =c(14,17,21,24,27,34,41,55,56),
      mazuff      =c(04,06,09,11,18,19,33,34,48),
      vov         =c(57,65,66,69,73,74,76,78),
      gazelle     =c(53,62,68,69,73,74,76,77),
      viper       =c(07,24,27,29,30,31,36,46),
      emmy        =c(16,20,25,32,37,39,40,42),
      titan       =c(33,38,43,46,60,63,70),
      soul        =c(65,66,69,73,74,76,78),
      wap         =c(37,40,42,53,71,72),
      poke        =c(38,43,60,63,64,70),
      psyko       =c(07,11,26,29,30,36),
      kult        =c(73,74,76,78),
      over        =c(63,64,70,71),
      orion       =c(36,78),
      jdawg       =c(71,72),
      fippmam     =c(62,67),
      magi        =c(67)
      )
    
    plot_ladle_wins <- function(at_least=5) {
      df <- data.frame(p=rep(paste(names(data)," (",sapply(data,length),")",sep=""),times=sapply(data,length)),
                       l=unlist(data,use.names=F),
                       c=unlist(sapply(data,function(x)(1:length(x))),use.names=F),
                       m=unlist(sapply(data,function(x)(rep(length(x),length(x)))),use.names=F))
      dfup <- df[df$m >= at_least,]
      bre <- unique(c(seq(from=1,to=max(dfup$c),by=4),max(dfup$c)))
      ggplot(dfup) + geom_point(aes(x=l,y=reorder(p,l),size=c,colour=c),shape=9) + 
        scale_colour_gradient('wins', guide="legend", breaks=bre) +
        scale_size_area('wins',breaks=bre) + 
        theme(axis.title.y=element_blank(),axis.ticks.x=element_blank(),axis.ticks.y=element_blank()) + 
        scale_x_continuous(breaks=c(1,seq(from=12,to=max(dfup$l),by=12)),minor_breaks=seq(from=1,to=max(dfup$l), by=1)) + 
        xlab(paste("Ladle trophies (",at_least,"+) sorted by players' activity\n", "(updated ", format(Sys.time(), "%Y/%m/%d"),")",sep=""))}
    
    plot_ladle_dominance <- function (last_ladle=(max(unlist(data,use.names=F))), months_ago=18, at_least=3) {
      data2 <- lapply(data,function(a)(a[a>(last_ladle-months_ago) & a<=last_ladle]))
      data2 <- data2[sapply(data2,length)>0]
      df2 <- data.frame(p=rep(paste(names(data2)," (",sapply(data2,length),")",sep=""),times=sapply(data2,length)),
                        l=unlist(data2,use.names=F),
                        c=unlist(sapply(data2,function(x)(1:length(x))),use.names=F),
                        m=unlist(sapply(data2,function(x)(rep(length(x),length(x)))),use.names=F))
      df2up <- df2[df2$m >= at_least,]
      ggplot(df2up) + geom_point(aes(x=l,y=reorder(p,c),size=c,color=c),shape=21,fill="Black") + 
        scale_x_continuous(breaks = seq(from = min(df2up$l), to = max(df2up$l), by = 1)) +
        theme(axis.title.y=element_blank(),panel.grid.minor=element_blank(),axis.ticks.x=element_blank(),axis.ticks.y=element_blank(),legend.position="none") +
        coord_fixed(1) +
        xlab(paste("Ladle dominance (",at_least,"+) in the last ",months_ago," months since L",last_ladle,"\n", "(updated ", format(Sys.time(), "%Y/%m/%d"),")",sep=""))}
    
    ### SAVE PLOTS
    ggsave("ladle_wins.png", plot_ladle_wins(), width=14, height=7, dpi=72, type="cairo-png")
    ggsave("ladle_dominance.png", plot_ladle_dominance(), width=14, height= 3.5, dpi=72, type="cairo-png")

3. Run the script. Two png plots will be saved