Skip to content

Commit

Permalink
Refactor out responses data into method
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbarton committed Feb 20, 2012
1 parent 9b5f3df commit cbd9ac7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 11 additions & 0 deletions 2012/lib/responses.r
@@ -0,0 +1,11 @@
country.data <- function(){
library(rworldmap)
data(countryExData)

responses <- read.csv('data/analytics.csv')
names(responses)[1] <- "Country"

subset(
merge(responses, countryExData[c('Country','ISO3V10')], by = "Country"),
Visits >= 5)
}
14 changes: 3 additions & 11 deletions 2012/plot/response_map.r
Expand Up @@ -4,20 +4,12 @@ library(rworldmap)
library(classInt)
library(RColorBrewer)

data(countryExData)

responses <- read.csv('data/analytics.csv')
names(responses)[1] <- "Country"

country.data <-
subset(
merge(responses, countryExData[c('Country','ISO3V10')], by = "Country"),
Visits >= 5)
source('lib/responses.r')

n.categories <- 5

intervals <- classIntervals(
country.data[["Visits"]],
country.data()[["Visits"]],
n = n.categories,
style = "jenks")

Expand All @@ -27,7 +19,7 @@ par(mai = c(0, 0, 0.2, 0), xaxs = "i", yaxs = "i")

mapCountryData(
joinCountryData2Map(
country.data,
country.data(),
joinCode = "ISO3",
mapResolution = "coarse",
nameJoinColumn = "ISO3V10"),
Expand Down

0 comments on commit cbd9ac7

Please sign in to comment.