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
# A simple scatter plot: | |
with(mtcars, plot(hp, mpg, col = "red")) | |
# Let's use paste() to build that same command as a string | |
dataSet <- "mtcars" | |
xVar <- "hp" | |
yVar <- "mpg" | |
plotCodeString <- paste("with(", dataSet, ", plot(", xVar, ", ", yVar, "))", | |
sep = "") # We'll leave out the col option |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("XML", "ggplot2", "lubridate", "reshape2", "scales") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Find your XML file from those listed at | |
# http://cdn.realclearpolitics.com/epolls/charts/ | |
URL <- "http://cdn.realclearpolitics.com/epolls/charts/1171.xml" | |
parsedXML <- xmlParse(URL) # First pass |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("XML", "ggplot2", "lubridate", "reshape2", "scales") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Find your XML file from those listed at | |
# http://cdn.realclearpolitics.com/epolls/charts/ | |
URL <- "http://cdn.realclearpolitics.com/epolls/charts/1171.xml" | |
parsedXML <- xmlParse(URL) # First pass |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Generate some randomly-distributed data | |
nObs <- 5000 | |
myData <- data.frame(X = rnorm(nObs), Y = rnorm(nObs)) | |
nClusters <- 7 # Cluster it | |
kMeans <- kmeans(myData, centers = nClusters) |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("maps", "ggplot2", "RColorBrewer") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
new_theme_empty <- theme_bw() # Create our own, mostly blank, theme | |
new_theme_empty$line <- element_blank() | |
new_theme_empty$rect <- element_blank() | |
new_theme_empty$strip.text <- element_blank() | |
new_theme_empty$axis.text <- element_blank() |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("ggplot2", "proxy") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
nIncrements <- 36 | |
eachIncrement <- seq(0, 1, len = nIncrements) | |
colorSweep <- expand.grid(eachIncrement, eachIncrement, eachIncrement) | |
moduloRemainder <- with(colorSweep, Var1*(nIncrements-1)) %% | |
floor(sqrt(nIncrements)) |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("reshape2", "ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Generate some data, which we'll load in a minute: | |
dataA <- matrix(rnorm(26*50), nrow = 26) | |
dataA <- t(apply(dataA, 1, cumsum)) | |
colnames(dataA) <- 1960:2009 | |
dataA <- data.frame(cName = LETTERS, cCode = 1:26*100, dataA) |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("ReadImages", "reshape", "ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
imageLoader <- function(url){ # This function takes a URL, and generates a data.frame with pixel locations and colors | |
# Download to disk, load | |
download.file(url, "tempPicture.jpg", mode = "wb") # Stash image locally | |
readImage <- read.jpeg("tempPicture.jpg") | |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("ReadImages", "reshape", "ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Image URL: | |
allImageURLs <- c("http://media.charlesleifer.com/blog/photos/thumbnails/akira_940x700.jpg", | |
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg", | |
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Official_portrait_of_Barack_Obama.jpg/441px-Official_portrait_of_Barack_Obama.jpg", | |
"http://cache.boston.com/universal/site_graphics/blogs/bigpicture/obama_11_05/obama22_16604051.jpg", |
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 # Change to FALSE if you don't want packages installed. | |
toInstall <- c("jpeg", "reshape2", "ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Image URL: | |
allImageURLs <- c("http://media.charlesleifer.com/blog/photos/thumbnails/akira_940x700.jpg", | |
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg", | |
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Official_portrait_of_Barack_Obama.jpg/441px-Official_portrait_of_Barack_Obama.jpg", | |
"http://cache.boston.com/universal/site_graphics/blogs/bigpicture/obama_11_05/obama22_16604051.jpg", |