-
Notifications
You must be signed in to change notification settings - Fork 20
/
02PlotDataSteps.R
75 lines (56 loc) · 1.96 KB
/
02PlotDataSteps.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
library(graphics)
library(tcltk)
library(pracma)
# Load the data generated by 01GenerateData.R
plot.data <- read.csv("GeneratedData/VoteDensity1200.csv", header=TRUE, stringsAsFactors=FALSE)
# Add padding above/below where there was data
# On top
top.padding <- 1:5
for (i in top.padding) {
plot.data <- cbind(0, plot.data)
}
# On bottom
bottom.padding <- 1:1
for (i in bottom.padding) {
plot.data <- cbind(plot.data, 0)
}
# On left
zero.row <- vector(mode="integer", length=dim(plot.data)[1])
left.padding <- 1:10
for (i in left.padding) {
plot.data <- rbind(zero.row, plot.data)
}
# On right
right.padding <- 1:10
for (i in left.padding) {
plot.data <- rbind(plot.data, zero.row)
}
max <- max(plot.data) # Max value in the data, used for scaling
plottingHeight <- 1000 # Arbitrary number that provides the graph's height
scaleFactor <- 300 # Discovered through trial and error to keep the graph in the boundaries
gap <- plottingHeight / length(plot.data) # Space between lines
# Output the file to a 36 inch by 24 inch SVG canvas
plot.width = 36
plot.height = 26.5
svg(filename = "./TestPlots/CanadaSGBigStairsBevel.svg", pointsize=12, width=plot.width, height=plot.height)
# Create a blank plot
yVals <- as.vector(plot.data[[1]] / max * scaleFactor)
plot(0, 0, xlim=c(0, length(yVals)), ylim=c(0,1100), type="n", las=1, xlab=NA, ylab=NA, bty="n", axes=FALSE)
plotting.threshold <- 0.1
plot.length = length(plot.data)
# Plot each line
for (i in 1:plot.length) {
# Grabs a row of data
yVals <- as.vector(plot.data[[i]] / max * scaleFactor)
xVals <- seq_along(yVals)
# yVals.smooth = savgol(yVals, 3, forder=4)
y2 <- rep(yVals, each=2)
y2 <- y2[-length(y2)]
x2 <- rep(xVals, each=2)[-1]
x3 <- c(min(x2), x2, max(x2))
y3 <- c(0, y2, 0)
polygon(x3, y3 + plottingHeight, border = NA, col = "#ffffff")
lines(x2, y2 + plottingHeight, col="#464646", lwd=0.5, type="s", cex=1, lend="square", ljoin="bevel" )
plottingHeight <- plottingHeight - gap
}
dev.off()