Skip to content

Instantly share code, notes, and snippets.

View cdesante's full-sized avatar

Christopher DeSante cdesante

  • Indiana University
View GitHub Profile
X <- 1:5
Y <- c(2, 5, 2.4, 3.67, 0.49)
qplot(X, weight=Y, geom="bar", ymin=0, xlab="X axis abel", ylab="Y axis label"
, main="MAIN LABEL")+ scale_y_continuous(limits=c(0, 5),breaks=c(1,2,3,4,5),labels=c("Strongly Disagree",
"Disagree","Neutral","Agree","Strongly Agree")) + theme_bw()
@cdesante
cdesante / scattergroup.R
Created June 20, 2012 17:26
Scatter Plots + lines by Group
library(ggplot2)
FEM <- c(rep(1, 100), rep(0, 100))
Gender <- c(rep("Female", 100), rep("Male", 100))
pid7 <- sample(0:6, 200, replace=T)
Bfem <- rnorm(200, 1.94, 0.37)
Bpid <- rnorm(200, -1.45, 0.82)
Binter <- rnorm(200, 0.31, .11)
B0 <- rnorm(200, 74.2, .29)
@cdesante
cdesante / customcolors.R
Created July 6, 2012 15:21
Time Series plots with custom breaks and colors
#by Christopher DeSante#
#Load ggplot2 #
library(ggplot2)
### X-axis: ###
anes.years <- c(1988, 1990, 1992, 1994, 2000, 2004, 2008,2016)
## Some DVs ##
mum1<-rnorm(8, 8,1)
mum2<-rnorm(8, 8,1)
@cdesante
cdesante / plotloop.R
Created July 13, 2012 21:18
Looping over plots with GGPLOT
#Set the working directory, plots will be saved locally.
library(ggplot2)
X <- rnorm(100)
Y <- rnorm(100)
Z <- rnorm(100)
A <- rnorm(100)
B <- rnorm(100)
@cdesante
cdesante / birthday.r
Created August 17, 2012 18:20
The Birthday Problem
#The birthday Problem.
#Simple computation:
N <- 1:50
pshare <- 1- exp(-(N*(N-1)/2)/365)
cbind(N, pshare)
#just want one value:
bday <- function(X){
N <- X
@cdesante
cdesante / hide them
Created August 28, 2012 17:03
hiding LaTeX secondary files
Run from the command prompt in Windows:
attrib +h *.bak /s
attrib +h *.blg /s
attrib +h *.aux /s
you can hide system files so all you see locally is the .tex and .pdf
@cdesante
cdesante / dyads.r
Created September 7, 2012 15:20
Plotting asymmetric dyad data
#This code produces a faceted plot of dyad-level data with asymmetry in the variable of interest across dyads.
MYDATA <- matrix(rnorm(16*16), 16, 16)
diag(MYDATA) <- rep(NA, 16)
MYDATA
colnames(MYDATA) <- rownames(MYDATA) <- LETTERS[1:16]
MYDATA
sender.row <- c()
receiver.col <- c()
value.to.plot <-c()
@cdesante
cdesante / basic.r
Created September 9, 2012 13:49
R as a calculator
#R as a giant awesome calculator:
4+5
exp(5)
log(10)
log(exp(6))
log(10, base=10)
sqrt(64)
pi^2
sqrt(pi^2)
pi
@cdesante
cdesante / dummy probit.r
Created September 14, 2012 19:19
Probit with indicator variable
###### Ordered Categorical DV: #####
#This uses "importance of aid to blacks" as a DV and race of R as the indicator IV.#
library(MASS)
white <- c(1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,
1,1,0,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,1,1,1,1,1,1,1,0,1,0,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,
0,1,1,0,1,1,1,1,1,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,
1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,
@cdesante
cdesante / weak.r
Created September 19, 2012 16:40
weakplot
is.R()
IQ <- round(rnorm(1000, 100, 15))
#IQ
plot(IQ)
plot(density(IQ), col="red")