Skip to content

Commit

Permalink
wip, split zone data into quantiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Berkoff committed Apr 12, 2015
1 parent 871dd1b commit dbd2810
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions master/master.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,11 @@ shinyServer(function(input, output, session){

# Read the zone data
data_ <- zones@data[[attrWithScenario(zone_attr, input$scenario)]]
# Sort it and save it as a matrix
data_ <- as.matrix(sort(data_))
# Divide the data_ matrix into four quartiles
quart <- round(length(data_) / 4)
# Create a new matrix for each quartile having the mean
m <- matrix(nrow=4,ncol=1)
m[1, 1] <- mean(data_[1:quart])
m[2, 1] <- mean(data_[quart:(quart * 2)])
m[3, 1] <- mean(data_[(quart * 2):(quart * 3)])
m[4, 1] <- mean(data_[(quart * 3):length(data_)])

b <- unique(quantile(data_, probs=seq.int(0,1, length.out=4)))
# Create a zone colour based on the absolute value of data (as data can be negative as well)
zone_col <- getColourRamp(c("red", "darkgreen"), abs(m))
zone_col <- getColourRamp(c("red", "darkgreen"), b)
# Barplot the data in vertical manner
barplot(m, names.arg = NA, col = zone_col, horiz=FALSE, xlab = "", ylab = zone_attr)
barplot(matrix(b, nrow=4,ncol=1), names.arg = NA, col = zone_col, horiz=FALSE, xlab = "", ylab = zone_attr)
}
})
})

0 comments on commit dbd2810

Please sign in to comment.