read.matrix <- function(file, header = FALSE, sep = "", skip = 0) { row.lens <- count.fields(file, sep = sep, skip = skip) if(any(row.lens != row.lens[1])) stop("number of columns is not constant") if(header) { nrows <- length(row.lens) - 1 ncols <- row.lens[2] col.names <- scan(file, what = "", sep = sep, nlines = 1, quiet = TRUE, skip = skip) x <- scan(file, sep = sep, skip = skip + 1, quiet = TRUE) } else { nrows <- length(row.lens) ncols <- row.lens[1] x <- scan(file, sep = sep, skip = skip, quiet = TRUE) col.names <- NULL } x <- as.double(x) if(ncols > 1) { dim(x) <- c(ncols,nrows) x <- t(x) colnames(x) <- col.names } else if(ncols == 1) x <- as.vector(x) else stop("wrong number of columns") return(x) } read.latencyplots <- function(dir = ".") { i <- 1 files <- dir(".") files <- sort(files, decreasing = TRUE) r = read.delim(files[1], sep = "\n") rows = dim(r)[1] + 1 z <- matrix(nrow = rows, ncol = length(files)) for (file in files) { m <- read.matrix(file=file) m[,1] <- 0 m <- apply(m, 1, max, na.rm = TRUE) z[,i] <- m i <- i + 1 } return(z) } data = read.latencyplots(dir = ".") data <- data + 0.1 data <- log10(data) z <- data x <- 1:nrow(z) x <- c(min(x) - 1e-10, x, max(x) + 1e-10) y <- 1:ncol(z) y <- c(min(y) - 1e-10, y, max(y) + 1e-10) z0 <- min(z) z <- rbind(z0, cbind(z0, z, z0), z0) fill <- matrix("green3", nrow = nrow(z)-1, ncol = ncol(z)-1) fill[ , i2 <- c(1,ncol(fill))] <- "gray" fill[i1 <- c(1,nrow(fill)) , ] <- "gray" par(bg = "slategray") fillfunc <- colorRampPalette(c("green", "yellow", "red"), space = "Lab", interpolate = "spline") fcol <- fill ; fcol[] <- fillfunc(nrow(fcol)) pdf("../3Dplot.pdf", paper = "special", width = 11.69, height = 8.26) par(fin = c(10.69, 7.26), mai = c(0.5, 0.5, 0.5, 0.5), ps = 12, pty = "m") persp(x, y, z, theta = 30, phi = 25, col = fcol, scale = FALSE, expand = 10 * nrow(z) / 200, nticks = 10, ticktype = "detailed", ltheta = -70, shade = 0.4, border = NA, box = TRUE, axes = TRUE, xlab = "Latency (us)", r = sqrt(3), zlab = "Frequency (log10)", ylab = "Repetitions") title(main = "3D plot", font.main = 4)