JRobertsDS
7/14/2020
The online App is here:
https://jrobertsds.shinyapps.io/DerbyStats/
The data for this project come from my Roller Derby officiating history, a data frame with rows of:
bankedRawData <- read.csv ("DBRefResumeBanked.csv", stringsAsFactors = FALSE)
flatRawData <- read.csv ("DBRefResumeFlat.csv", stringsAsFactors = FALSE)
with (bankedRawData, bankedGameData <<- data.frame (Date = as.POSIXct(Date, format="%m/%d/%Y"),
Game = "Banked", HR = HR, Position = Position, Bout = Bout, Notes = With.Whom, Add.Notes = Notes))
with (flatRawData[-13, ], flatGameData <<- data.frame (Date = as.POSIXct(Bout.Date, format="%m/%d/%Y"),
Game = "Flat", HR = HR, Position = Position, Bout = Bout, Notes = Notes, Add.Notes = paste (More.Notes, X)))
gameData <- rbind (bankedGameData, flatGameData)
HRs <- count (gameData, HR) %>% arrange (desc (n))
Positions <- count (gameData, Position) %>% arrange (desc (n))
str (gameData)
'data.frame': 213 obs. of 7 variables:
$ Date : POSIXct, format: "2010-02-06" "2010-03-05" ...
$ Game : Factor w/ 2 levels "Banked","Flat": 1 1 1 1 1 1 1 1 1 1 ...
$ HR : Factor w/ 44 levels "Anna Mean Gables",..: 8 24 24 24 8 19 24 5 24 3 ...
$ Position : Factor w/ 23 levels "Alt","BPR","EYE",..: 15 13 13 16 14 16 11 16 4 11 ...
$ Bout : Factor w/ 176 levels "ACDG JRs at Dollinquents",..: 49 72 77 97 90 111 7 94 11 76 ...
$ Notes : Factor w/ 124 levels "","All MVP Roster",..: 37 38 40 1 37 1 61 1 44 61 ...
$ Add.Notes: Factor w/ 46 levels ""," Chrome cacheing bug, and buggy SB / PT interaction",..: 1 1 1 1 1 18 1 1 1 1 ...
ui <- fluidPage(
titlePanel("Derby Stats"),
sidebarLayout(
sidebarPanel(
h5 ("Choose the number of bars to view:"),
sliderInput("topHits", "Number of Bars:",
min = 4, max = max (length (HRs$n), length (Positions$n)), step = 1, value = 10),
h5 ("Choose the type of chart to view:"),
radioButtons("whichChart", "Show HRs, or Positions:",
c("HRs" = "HRs", "Positions" = "Positions"))
),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
#initialize
topHits = 10
whichChart = "HRs"
output$distPlot <- renderPlot({
if (input$whichChart == "Positions") {
...
} else {
topHits <- min (input$topHits, length (HRs$n))
graphTitle = sprintf ("Top %d ", topHits)
graphTitle <- paste(graphTitle, "Head Referees")
gameData[gameData$HR %in% HRs[1:input$topHits, ]$HR, ] %>%
ggplot(.) + geom_bar(aes(x = reorder (HR, HR, function (x) - length(x)), fill = Game), position = "stack") + theme(axis.text.x = element_text(angle = 90)) + xlab ("Head Referee") + ylab ("Count") + ggtitle (graphTitle)
}
})
}