-
-
Save ptoche/8303340 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
# server.R | |
library("shiny") | |
library("ggplot2") # Grammar of Graphics for plots | |
library("eeptools") # Convenience functions for education data | |
# static function | |
rnormcor <- function(x,rho) {rnorm(1,rho*x,sqrt(1-rho^2))} | |
shinyServer( | |
function(input,output){ | |
output$distPlot <- renderPlot({ | |
a <- rnorm(input$obs) | |
b <- sapply(a, rnormcor, rho = input$rho) | |
p <- qplot(a, b, alpha = 0.5) | |
p <- p + scale_alpha(guide = "none") | |
p <- p + geom_smooth(method = "lm", se = TRUE, level = .99 | |
, fill = "blue", colour = "darkblue", alpha = 0.2, size = 1) | |
p <- p + theme_dpi() | |
p <- p + labs(x = "", y = "", title = paste0("Correlation = ", input$rho, ", Confidence Level = .99")) | |
# p <- p + geom_text(aes(x = -1, y = 3, label = paste0("Corr. = ", input$rho)), size = 8) | |
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
# https://gist.github.com/jknowles/4484910 | |
# ui.R | |
library("shiny") | |
library("ggplot2") # Grammar of Graphics for plots | |
library("eeptools") # Convenience functions for education data | |
shinyUI( | |
pageWithSidebar( | |
headerPanel(h3("Exploring Properties of Distributions")) | |
, | |
sidebarPanel( | |
sliderInput("obs" | |
, "Number of observations:" | |
, min = 200 | |
, max = 5000 | |
, value = 500 | |
, step = 250 | |
) | |
, br(), br(), | |
sliderInput("rho" | |
, "Correlation Coefficient" | |
, min = -1 | |
, max = 1 | |
, value = 0 | |
, step = 0.1 | |
) | |
) | |
, | |
mainPanel(plotOutput("distPlot")) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very nice app by jknowles, thanks for sharing! marginal edits above