Created
April 24, 2024 20:52
-
-
Save samcofer/e33c7a4f2038a4c04cd5a10d8a360676 to your computer and use it in GitHub Desktop.
Shiny Geyser with ggplot
This file contains hidden or 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
# Load necessary libraries | |
library(ggplot2) | |
library(shiny) | |
# Load Old Faithful geyser data | |
data <- faithful | |
# Define UI | |
ui <- fluidPage( | |
titlePanel("Old Faithful Geyser Data"), | |
sidebarLayout( | |
sidebarPanel( | |
sliderInput("bins", | |
"Number of bins:", | |
min = 1, | |
max = 50, | |
value = 30) | |
), | |
mainPanel( | |
plotOutput("distPlot") | |
) | |
) | |
) | |
# Define server logic | |
server <- function(input, output) { | |
output$distPlot <- renderPlot({ | |
# Create a histogram of the eruption durations with ggplot2 | |
ggplot(data, aes(x = waiting)) + | |
geom_histogram(binwidth = diff(range(data$waiting)) / input$bins, fill = "skyblue", color = "black") + | |
labs(title = "Histogram of Old Faithful Eruption Durations", x = "Eruption Duration (minutes)", y = "Frequency") + | |
theme(text=element_text(size=16, family="mono")) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment