View diet.r
######################################################## | |
##### Author: Diego Valle Jones | |
##### Website: www.diegovalle.net | |
##### Date Created: Mon Mar 01 18:51:27 2010 | |
######################################################## | |
#1. For what foods are Americans and Mexicans outliers | |
#2. Partition the data around medoids to classify the | |
#countries of the world according to what they eat | |
library(ggplot2) |
View mls_analysis.R
# ANALYSIS OF MAJOR LEAGUE SOCCER | |
# MOTIVATION: http://thelogcabin.wordpress.com/2010/08/16/goals-per-game-in-mls/ | |
# http://thelogcabin.wordpress.com/2010/08/23/a-rule-change-in-major-league-soccer/ | |
# LOAD ALL REQUIRED LIBRARIES | |
library(XML); | |
library(reshape); |
View Unemployment.R
plot.heat <- function(tmp,state.map,z,title=NULL,breaks=NULL,cex.legend=1,bw=.2,col.vec=NULL,main=NULL,plot.legend=TRUE, ...) { | |
tmp@data$zCat <- cut(tmp@data[,z],breaks,include.lowest=TRUE) | |
cutpoints <- levels(tmp@data$zCat) | |
if (is.null(col.vec)) col.vec <- heat.colors(length(levels(tmp@data$zCat))) | |
cutpointsColors <- col.vec | |
levels(tmp@data$zCat) <- cutpointsColors | |
cols <- as.character(tmp$zCat) | |
##cols <- "white" | |
plot(tmp,border=cols, lwd=bw,axes = FALSE, las = 1,col=as.character(tmp@data$zCat),main="A", ...) | |
if (!is.null(state.map)) { |
View merge_sp_df.R
sp@data = data.frame(sp@data, df[match(sp@data[,by], df[,by]),]) |
View plotreg2.R
# load libraries | |
library(ggplot2); | |
library(Zelig); | |
# function to extract coefficients of a zelig model | |
sd.coef2 = function(x){ | |
est = summary(x)$coef[,1]; |
View economist_bunfight.R
economist = theme_update(plot.background = theme_rect(fill = 'lightblue', | |
colour = 'black'), | |
panel.background = theme_rect(fill = 'lightblue', | |
colour = NA), | |
axis.text.x = theme_text(colour = 'black', | |
size = base_size * 0.8, | |
lineheight = 0.9, | |
vjust = 1), | |
axis.text.y = theme_text(colour = 'black', | |
size = base_size * 0.8, |
View bunfight.csv
country | loccurover | text | |
---|---|---|---|
Switzerland | 80 | 6.78 | |
Brazil | 40 | 5.26 | |
Euro area | 30 | 4.79 | |
Canada | 10 | 4.18 | |
Japan | 5 | 3.91 | |
United States | 0 | 3.71 | |
Britain | -5 | 3.63 | |
Singapore | -10 | 3.46 | |
South Korea | -20 | 3.03 |
View nhl_skaters.R
# LOAD LIBRARIES REQUIRED | |
library(plyr); | |
library(XML) | |
# FIGURE OUT PATTERN OF URL FOR EACH SEASON | |
url.b1 = 'http://ca.sports.yahoo.com/nhl/stats/byposition?pos=C,RW,LW,D'; | |
url.b2 = '&sort=14&conference=NHL&year=season_'; | |
url.b3 = y; |
View example1.R
# Load Data | |
poly = readShapeSpatial('1_data/maps/Precincts.shp'); | |
df = read.csv('1_data/precincts.csv'); | |
# Clean Data | |
df = df[,-grep('count', names(df))]; | |
names(df) = sub('_pct', '', names(df)); | |
# Plot Choropleth | |
choro1 = plotChoropleth(.poly = poly, .df = df, |
View example2.R
# Panel of Choropleth Maps using Facets | |
# Plot Rahm Emnauel and Gery Chico | |
choro2 = plotChoropleth(.poly = chicago, .df = df, | |
id1 = list('WARD', 'PRECINCT'), | |
id2 = list('ward', 'precinct'), | |
field = c('emanuel', 'chico'), | |
title = 'Chicago Mayoral Election 2011', | |
legtitle = 'Votes %', | |
colpal = 'Blues', n = 5, style = 'pretty') + | |
opts(legend.position = c(0.15, 0.25)); |
OlderNewer