Skip to content

Instantly share code, notes, and snippets.

View MichaelMBishop's full-sized avatar

Michael Bishop MichaelMBishop

View GitHub Profile
@MichaelMBishop
MichaelMBishop / Marimekko.R
Created October 17, 2012 23:59 — forked from dsparks/Marimekko.R
Simplest marimekko/mosaic plot
# Simplest possible marimekko/mosaic plot
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("vcd", "ggplot2", "RColorBrewer")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
theme_set(theme_gray(base_size = 7))
# All you need to start with is individual count data, and a grouping variable
@low-decarie
low-decarie / anonym
Created May 5, 2012 03:48
anonymize a data.frame
#http://stackoverflow.com/questions/10454973/how-to-create-example-data-set-from-private-data-replacing-variable-names-and-l/10458688#10458688
anonym<-function(df){
if(length(df)>26){
LETTERS<-replicate(floor(length(df)/26),{LETTERS<-c(LETTERS, paste(LETTERS, LETTERS, sep=""))})
}
names(df)<-paste(LETTERS[1:length(df)])
level.id.df<-function(df){
level.id<-function(i){
mid_range <- function(x) mean(range(x, na.rm = TRUE))
centres <- ddply(county_df, c("state", "county"), summarise,
lat = mid_range(lat),
long = mid_range(long)
)
bubbles <- merge(centres, unemp, by = c("state", "county"))
ggplot(bubbles, aes(long, lat)) +
geom_polygon(aes(group = group), data = state_df,
colour = "white", fill = NA) +