R file requires myFluc2
From Ucsbgalaxy
myFluc2<-function (table, type = "size", floor = 0, ceiling = max(table$freq,
na.rm = TRUE))
{
if (is.table(table))
table <- as.data.frame(t(table))
oldnames <- names(table)
names(table) <- c("x", "y", "result")
table <- add.all.combinations(table, list("x", "y"))
table <- transform(table, x = as.factor(x), y = as.factor(y),
freq = result)
if (type == "size") {
table <- transform(table, freq = sqrt(pmin(freq, ceiling)/ceiling),
border = ifelse(is.na(freq), "grey90", ifelse(freq >
ceiling, "grey30", "grey50")))
table[is.na(table$freq), "freq"] <- 1
table <- subset(table, freq * ceiling >= floor)
}
if (type == "size") {
nx <- length(levels(table$x))
ny <- length(levels(table$y))
p <- ggplot(table, aes_string(x = "x", y = "y", height = "freq/2",
width = "freq/2", fill = "border")) + geom_tile(colour = "white") +
scale_fill_identity() + opts(aspect.ratio = ny/nx, legend.position="none") + xlab("") + ylab("")
}
else {
p <- ggplot(table, aes_string(x = "x", y = "y", fill = "freq")) +
geom_tile(colour = "grey50") + scale_fill_gradient2(low = "white",
high = "darkgreen")
}
p$xlabel <- oldnames[1]
p$ylabel <- oldnames[2]
p
}