Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# jknowles/server.R

Created Jan 8, 2013
Demonstrating bi-variate correlations using simulation.
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
 # Script to demonstrate distributions library(eeptools) library(shiny) library(ggplot2) rnormcor <- function(x,rho) rnorm(1,rho*x,sqrt(1-rho^2)) shinyServer(function(input,output){ output\$distPlot<-reactivePlot(function(){ a<-rnorm(input\$obs) b<-sapply(a,rnormcor,rho=input\$rho) p<-qplot(a,b,alpha=0.85)+geom_smooth(method="lm",se=FALSE,size=1.1)+theme_dpi() p<-p+labs(x="",y="",title="Demonstrating Correlations") p<-p+geom_text(aes(x=-2.5,y=3,label=paste("Corr. =",input\$rho,sep=" ")),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
 # Script to demonstrate distributions library(eeptools) library(shiny) library(ggplot2) shinyUI(pageWithSidebar( # Title headerPanel("Simulating Data with Correlation"), sidebarPanel( sliderInput("obs","Number of observations:", min=200,max=5000,value=500,step=250), sliderInput("rho","Correlation Coefficient", min=-1,max=1,value=0,step=0.1) ), # GGPLOT mainPanel( plotOutput("distPlot") ) ))
to join this conversation on GitHub. Already have an account? Sign in to comment