Skip to content

Instantly share code, notes, and snippets.

View cdesante's full-sized avatar

Christopher DeSante cdesante

  • Indiana University
View GitHub Profile
@cdesante
cdesante / basicmap.r
Created December 10, 2012 17:55
basic map
doInstall <- TRUE
toInstall <- c("maps", "ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
library(maps)
Prison <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/prison.csv")
head(Prison)
@cdesante
cdesante / hjustvjust.r
Created November 14, 2012 05:52
hjustvjust
hjustvjust <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
text="is-R"
)
hv <- ggplot(hjustvjust, aes(x=hjust, y=vjust)) +
geom_point() +
@cdesante
cdesante / ggd2g1.r
Created October 23, 2012 18:11
color1
#######################################################
# Example 4: Casting/Melting with custom functions #
#######################################################
#Let's first define a function, SE, to represent the standard error of a
#variable:
library(gridExtra)
library(ggplot2)
SE <- function(X) {
(sd(X, na.rm=TRUE)/ sqrt(length(X)-1) )
@cdesante
cdesante / rPackages
Created April 24, 2020 14:49
Reinstalling All Packages for R 4.0
#In R 3.6, run:
.libPaths()[1]
#Copy this directory path and paste it on the line below;
#Then run all lines below in R 4.0:
PASTED <- "C:/Users/.../R/win-library/3.6"
currentPackages <- list.dirs(path = PASTED , recursive = FALSE)
currentPackages
trimmed <- stringr::str_replace_all(currentPackages, paste(PASTED , "/", sep = ""), "")
toInstall <- dput(trimmed)
doInstall <- TRUE
@cdesante
cdesante / outliers.r
Created September 9, 2012 14:52
Basic Plot in R with Conditional Coloring
#Plotting Random Variables
#rnorm(N, mean, sd): generates a
#random normal variable of length N
#with specified mean and std. dev. (sd)
# x/ylim = range of X/Y axis.
#col: colors, specified with an ifelse()
#pch, plot symbol to use
#pch list: http://voteview.com/symbols_pch.htm
X <- rnorm(500) #draw var 1
@cdesante
cdesante / newVersion.R
Last active June 6, 2019 14:51
newVersion
install.packages("tidyr", dependencies = TRUE)
install.packages("ggplot2", dependencies = TRUE)
install.packages("survey", dependencies = TRUE)
install.packages("gridExtra", dependencies = TRUE)
install.packages("dplyr", dependencies = TRUE)
install.packages("stringr", dependencies = TRUE)
install.packages("tidytext", dependencies = TRUE)
install.packages("mvtnorm", dependencies = TRUE)
install.packages("foreign", dependencies = TRUE)
install.packages("Zelig", dependencies = TRUE)
@cdesante
cdesante / ggd3g1.r
Created October 23, 2012 19:57
color3
X <- c(1)
Y <- c(1)
DF <- as.data.frame(cbind(X,Y))
c.1 <- ggplot(data = DF) + geom_bar(aes(x = X, y = Y, fill = factor(X))) + coord_flip() + theme(legend.position="none") + labs(x="", y="", title="One Colour") + scale_y_continuous(breaks=NULL, expand=c(0,0)) + scale_x_continuous(breaks=NULL, expand=c(0,0))
X <- c(1:2)
Y <- rep(1, length(X))
DF <- as.data.frame(cbind(X,Y))
@cdesante
cdesante / shadycats.r
Created September 19, 2012 16:38
Greek and Variables in Plot Titles
shade.norm <- function(MU, SD, Lower, Upper, fill.color) {
cord.x <- c(Lower,seq(Lower,Upper,0.01),Upper)
cord.y <- c(0,dnorm(seq(Lower,Upper,0.01),
mean = MU, sd = SD),0)
y.axis.text <-bquote("Density of N " * " " * "(" *
mu * " " * "=" * " " * .(MU) * ","* " " * sigma *
" " * "=" * " " * .(SD) * ")")
@cdesante
cdesante / turkey2016.r
Last active February 28, 2018 15:50
library(ggplot2)
theme_set(theme_bw())
Turkey <- read.csv("http://pages.iu.edu/~cdesante/turkey.csv")
ggplot(data = Turkey) + geom_tile(aes(x = Happy, y = Thanksgiving, fill=Turkey.Colors
)) + scale_fill_identity() + theme_bw() + labs(title = "Happy Thanksgiving 2016 from is.R()!\n",
x = "", y = "") + scale_x_continuous(breaks = NULL)+ scale_y_continuous(breaks = NULL)
@cdesante
cdesante / ggd5g2.r
Created November 1, 2012 17:11
Brewer Pallettes
#Load ggplot default data: Diamonds
library(ggplot2)
library(gridExtra)
data(diamonds)
head(diamonds)
diamonds <- diamonds[diamonds$color < "J",]
#http://127.0.0.1:25615/library/ggplot2/html/diamonds.html
B1 <- ggplot(data = diamonds ) + geom_point(aes( x = carat, y = price, color=color)