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
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) |
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
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() + |
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
####################################################### | |
# 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) ) |
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
#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 |
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
#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 |
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
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) |
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
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)) |
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
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) * ")") |
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
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) |
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
#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) |
NewerOlder