Skip to content

Instantly share code, notes, and snippets.

@jrnold
Last active May 6, 2020 18:39
Show Gist options
  • Save jrnold/7131444 to your computer and use it in GitHub Desktop.
Save jrnold/7131444 to your computer and use it in GitHub Desktop.
Shiny app comparing the t-distribution to the normal distribution
library("shiny")
x <- seq(-4, 4, by=0.01)
norm_dens <- dnorm(x)
shinyServer(function(input, output) {
output$plot <- renderPlot({
t_dens <- dt(x, df = input$df)
print(ggplot()
+ geom_line(data = data.frame(x = x, y = norm_dens),
mapping = aes(x = x, y = y), colour = "blue")
+ geom_line(data = data.frame(x = x, y = t_dens),
mapping = aes(x = x, y = y), colour = "red")
+ ggtitle(sprintf("Student t-distribution (df = %d)", input$df)))
})
})
library("shiny")
library("ggplot2")
shinyUI(bootstrapPage(
sliderInput(inputId = "df",
label = "Degrees of Freedom",
min = 1, max = 50, value = 1, step = 1,
animate=animationOptions(interval=800, loop=T)),
plotOutput("plot")
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment