Skip to content

Commit

Permalink
added use.3d switcher to parasim.plot.* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
papousek committed May 8, 2013
1 parent 189fb1c commit 06ecffa
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions R/parasim.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
library("rgl");

parasim.plot.data <- function(x, y, robustness, z = NULL, ...) {
ok.filter <- robustness > 0;
nok.filter <- robustness <= 0;
if (is.null(z)) {
ok.data <- data.frame(x = x[ok.filter], y = y[ok.filter], robustness = robustness[ok.filter]);
nok.data <- data.frame(x = x[nok.filter], y = y[nok.filter], robustness = robustness[nok.filter]);
parasim.color.redRamp <- colorRamp(c("#FF9900","#770000"))
parasim.color.greenRamp <- colorRamp(c("#99FF00","#007700"))

parasim.robustColor <- function(robustness, robustness.max = NULL, robustness.min = NULL) {
if (is.null(robustness.max)) {
robustness.max <- max(robustness)
}
if (robustness.max == 0) {
robustness.max <- 1;
}
if (is.null(robustness.min)) {
robustness.min <- min(robustness)
}
if (robustness.min == 0) {
robustness.min <- -1;
}
mapply(
function(x) {
col <- if (x > 0) {
parasim.color.greenRamp(x/robustness.max)
} else {
parasim.color.redRamp(abs(x/robustness.min))
}
rgb(col, maxColorValue=255)
},
robustness);
}

parasim.plot.data <- function(x, y, robustness, z = NULL, use.3d = TRUE, ...) {
if (use.3d || !is.null(z)) {
ok.filter <- robustness > 0;
nok.filter <- robustness <= 0;
if (is.null(z)) {
ok.data <- data.frame(x = x[ok.filter], y = y[ok.filter], robustness = robustness[ok.filter]);
nok.data <- data.frame(x = x[nok.filter], y = y[nok.filter], robustness = robustness[nok.filter]);
} else {
ok.data <- data.frame(x = x[ok.filter], y = y[ok.filter], z = z[ok.filter]);
nok.data <- data.frame(x = x[nok.filter], y = y[nok.filter], z = z[nok.filter]);
}
plot3d(ok.data, col="green", ...);
plot3d(nok.data, col="red", add=TRUE, ...);
} else {
ok.data <- data.frame(x = x[ok.filter], y = y[ok.filter], z = z[ok.filter]);
nok.data <- data.frame(x = x[nok.filter], y = y[nok.filter], z = z[nok.filter]);
plot(x, y, col = parasim.robustColor(robustness), pch=20, ...);
}
plot3d(ok.data, col="green", ...);
plot3d(nok.data, col="red", add=TRUE, ...);
}

parasim.plot.csv <- function(file, x.name, y.name, z.name = "", robustness.name = "Robustness", ...) {
parasim.plot.csv <- function(file, x.name, y.name, z.name = NULL, robustness.name = "Robustness", use.3d = TRUE, ...) {
data <- read.table(file, header=TRUE);
if (z.name != "") {
parasim.plot.data(data[x.name], data[y.name], data[robustness.name], z = data[z.name], ...);
if (!is.null(z.name)) {
parasim.plot.data(data[[x.name]], data[[y.name]], data[[robustness.name]], z = data[[z.name]], use.3d = use.3d, ...);
} else {
parasim.plot.data(data[x.name], data[y.name], data[robustness.name], ...);
parasim.plot.data(data[[x.name]], data[[y.name]], data[[robustness.name]], use.3d = use.3d, ...);
}
}

Expand Down

0 comments on commit 06ecffa

Please sign in to comment.