Skip to content

Instantly share code, notes, and snippets.

@bayesball
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayesball/5aa5ca3c7098c56b6604 to your computer and use it in GitHub Desktop.
Save bayesball/5aa5ca3c7098c56b6604 to your computer and use it in GitHub Desktop.
Shiny application to plot a trajectory of a home run hitter
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)
}
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)
})
}
)
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