library(tidyverse)
library(readxl)
library(lubridate)

# https://blogs.reed.edu/ed-tech/2015/10/creating-nice-tables-using-r-markdown/
library(knitr) #kable
#library(xtable) # xtable: generate LaTeX code to output table into PDF  

library(highcharter)



My Statistical Analysis for My Poker Statistics


This visualization is interactive in the way that the plots are responsive to the movement of the curser, with corresponding information displayed.


1. Data Preparation

Create dataset in Google Sheet, download to the folder as excel document

#filePath <- file.choose()
filePath <- "/Users/apple/Desktop/YuqingRWork/Poker/Borgata2022.xlsx"  # 
GoogleSheet <- read_excel(filePath)

BorgataXue <- GoogleSheet %>% mutate(Date = ymd(Date),
                             sesLength = round( as.numeric(sesEnd - sesStart) - pause/60, 2), #directly substract times
                             Profit = cashOut - buyIn, 
                             profitPerHr = round(Profit/sesLength,2),
                             accuHour = cumsum(sesLength),
                             accuProfit = cumsum(Profit), 
                             accuProfitPerHr = accuProfit/accuHour
)
#options(tibble.width = Inf)  
#options(tibble.print_max = 15, tibble.print_min = 5) # if more than 15 rows, print 5 rows
BorgataXue
## # A tibble: 28 × 17
##    Date       Day   effectDay sesStart            sesEnd              buyIn
##    <date>     <chr> <chr>     <dttm>              <dttm>              <dbl>
##  1 2022-06-13 Mon   Mon       2022-06-13 18:28:00 2022-06-13 23:18:00   800
##  2 2022-06-15 Wed   Wed       2022-06-15 11:47:00 2022-06-15 20:00:00  1200
##  3 2022-06-16 Thu   Thu       2022-06-16 16:58:00 2022-06-17 01:03:00  1800
##  4 2022-06-21 Tue   Tue       2022-06-21 21:23:00 2022-06-22 03:30:00  1000
##  5 2022-06-22 Wed   Wed       2022-06-22 22:10:00 2022-06-23 00:51:00  1000
##  6 2022-07-02 Sat   Sat       2022-07-02 18:23:00 2022-07-03 00:33:00  1800
##  7 2022-07-03 Sun   Sun       2022-07-03 23:46:00 2022-07-04 07:25:00  1100
##  8 2022-07-04 Mon   Mon       2022-07-04 23:55:00 2022-07-05 06:47:00  1000
##  9 2022-07-07 Thu   Thu       2022-07-07 20:48:00 2022-07-08 04:20:00  1000
## 10 2022-07-12 Tue   Tue       2022-07-12 22:22:00 2022-07-13 05:29:00  1400
## # … with 18 more rows, and 11 more variables: cashOut <dbl>, pause <dbl>,
## #   Holiday <dbl>, Trip <dbl>, drinkTip <dbl>, sesLength <dbl>, Profit <dbl>,
## #   profitPerHr <dbl>, accuHour <dbl>, accuProfit <dbl>, accuProfitPerHr <dbl>
## # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names


1.Session Profit

series = list(
  list(
    name = 'Profit for each session',
    color = '#1E90FF', # <http://cloford.com/resources/colours/500col.htm>
    data = BorgataXue %>% select(Profit)  %>% .[[1]]
  )
)
highchart() %>%
  hc_add_series_list(series) %>% 
  hc_xAxis(categories = BorgataXue %>% select(Date) %>% .[[1]] ) %>%
  hc_yAxis(plotLines = list(
              list(value = 0, width = 5, color = 'black')
              ))

2. Accumulated Profit

#command+shift+c
#library(highcharter)
series = list(
  list(
    name = 'Accumulated Profit',
    color = '#1E90FF', # <http://cloford.com/resources/colours/500col.htm>
    data = BorgataXue %>%
            select(accuProfit)  %>% .[[1]]
  )
)

highchart() %>%
  hc_add_series_list(series) %>%
  hc_xAxis(categories = BorgataXue %>% select(Date) %>% .[[1]] ) %>%
  hc_yAxis(plotLines = list(
              list(value = 0, width = 5, color = 'black')
              ))

3. Accumulated Profit per hour

#library(highcharter)
series = list(
  list(
    name = 'Accumulated Profit',
    color = '#1E90FF', # <http://cloford.com/resources/colours/500col.htm>
    data = BorgataXue %>% select(accuProfitPerHr)  %>% .[[1]]
  )
)

highchart() %>%
  hc_add_series_list(series) %>%
  hc_xAxis(categories = BorgataXue %>% select(Date) %>% .[[1]] ) %>%
  hc_yAxis(plotLines = list(
              list(value = 0, width = 5, color = 'black')
              ))

1.B post- Jul 28

1.Session Profit

** create each sub dataset for each trip number, for accumulaye profit**

series = list(
  list(
    name = 'Profit for each session',
    color = '#1E90FF', # <http://cloford.com/resources/colours/500col.htm>
    data = BorgataXue %>%
            filter (Trip == 5) %>% select(Profit)  %>% .[[1]]
  )
)
highchart() %>%
  hc_add_series_list(series) %>% 
  hc_xAxis(categories = BorgataXue %>% select(Date) %>% .[[1]] ) %>%
  hc_yAxis(plotLines = list(
              list(value = 0, width = 5, color = 'black')
              ))