Last active
August 29, 2015 14:21
-
-
Save bayesball/5aa5ca3c7098c56b6604 to your computer and use it in GitHub Desktop.
Shiny application to plot a trajectory of a home run hitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot.trajectory <- function(player){ | |
d <- subset(sluggerdata, Player==player) | |
p <- ggplot(d, aes(Age, HR/AB)) + | |
geom_point(size=4, color="red") + | |
geom_smooth(size=2, color="blue") + | |
labs(title = player) | |
print(p) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(LearnBayes) | |
library(ggplot2) | |
source("helpers.R") | |
shinyServer( | |
function(input, output) { | |
output$map <- renderPlot({ | |
player <- switch(input$var, | |
"Hank Aaron" = "Aaron", | |
"Hank Greenberg" = "Greenberg", | |
"Harmon Killebrew" = "Killebrew", | |
"Mickey Mantle" = "Mantle", | |
"Willie Mays" = "Mays", | |
"Willie McCovey" = "McCovey", | |
"Mel Ott" = "Ott", | |
"Babe Ruth" = "Ruth", | |
"Mike Schmidt" = "Schmidt", | |
"Sammy Sosa" = "Sosa") | |
plot.trajectory(player) | |
}) | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shinyUI(fluidPage( | |
titlePanel("Home Run Trajectories"), | |
sidebarLayout( | |
sidebarPanel( | |
helpText("Graph Trajectory of a Famous Slugger"), | |
selectInput("var", | |
label = "Choose a Slugger", | |
choices = c("Hank Aaron", "Hank Greenberg", | |
"Harmon Killebrew", "Mickey Mantle", | |
"Willie Mays", | |
"Willie McCovey", "Mel Ott", "Babe Ruth", | |
"Mike Schmidt", "Sammy Sosa"), | |
selected = "Mike Schmidt") | |
), | |
mainPanel(plotOutput("map")) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment