Created
April 15, 2014 19:40
-
-
Save ramnathv/10764200 to your computer and use it in GitHub Desktop.
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
# install.packages("Lahman") | |
data(Teams, package = "Lahman") | |
library(ggplot2) | |
plot_team <- function(teamID){ | |
p0 <- ggplot() + | |
geom_point( | |
mapping = aes( | |
x = yearID, | |
y = SO/G | |
), | |
color = "gray70", | |
data = Teams | |
) | |
library(plyr) | |
team_year_sog <- ddply( | |
Teams, | |
"yearID", | |
summarize, | |
y = mean(SO/G) | |
) | |
p1 <- p0 + | |
geom_line( | |
mapping = aes( | |
x = yearID, | |
y = y | |
), | |
data = team_year_sog | |
) | |
p1 + | |
geom_line( | |
mapping = aes( | |
x = yearID, | |
y = SO/G | |
), | |
data = Teams[Teams$teamID == teamID,], | |
color = 'darkorange' | |
) | |
} | |
install.packages('shiny') | |
library(shiny) | |
ui <- pageWithSidebar( | |
headerPanel(""), | |
sidebarPanel( | |
selectInput( | |
"teamID", | |
"Team ID", | |
unique(Teams$teamID) | |
) | |
), | |
mainPanel( | |
plotOutput("dummy") | |
) | |
) | |
server <- function(input, output){ | |
output$dummy <- renderPlot({ | |
print(plot_team(input$teamID)) | |
}) | |
} | |
runApp(list( | |
ui = ui, | |
server = server | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment