-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotData.R
More file actions
79 lines (65 loc) · 2.83 KB
/
PlotData.R
File metadata and controls
79 lines (65 loc) · 2.83 KB
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
75
76
77
78
79
## File:PlotData.R
## Purpose: Plot the data for quick examination and print it to separate files for use in report.
Plotting <- function(baseline, bond, helicopter, permanent, title, texts, legend_pos = "none", usePercent = FALSE) {
baseline_color <- "black"
bond_color <- "red"
helicopter_color <- "green"
permanent_color <- "yellow"
baseline_lty <- 1
bond_lty <- 1
helicopter_lty <- 2
permanent_lty <- 3
years <- 1:length(baseline) - 1
if (length(helicopter) > 0) {
ymin <- min(baseline, bond, helicopter)
ymax <- max(baseline, bond, helicopter)
} else {
ymin <- min(baseline, bond)
ymax <- max(baseline, bond)
}
scaleFactor = 1
ylabel = ""
if (usePercent) {
scaleFactor = 100
ylabel = "%"
}
plot(years, scaleFactor * baseline, type = "l", lty = baseline_lty, col = baseline_color, main = title, xlab = "Year", ylab = ylabel,
ylim = scaleFactor * c(ymin, ymax))
lines(years, scaleFactor * bond, lty = bond_lty, col = bond_color)
if (length(helicopter) > 0) {
lines(years, scaleFactor * helicopter, col = helicopter_color, lty = helicopter_lty)
}
#lines(years, scaleFactor *permanent, col = permanent_color, lty = permanent_lty)
if (legend_pos != "none") {
legend(legend_pos, legend = texts,
col = c(baseline_color, bond_color, helicopter_color),
lty = c(baseline_lty, bond_lty, helicopter_lty), cex = 0.8)
}
}
PlotData <- function(result_baseline, result_bond, result_helicopter, result_permanent, parameters) {
titles = c("Output gap", "Inflation", "Nominal interest rate", "OMO/GDP", "Monetary base/GDP", "Debt/GDP", "Transfers/GDP", "Real interest rate")
lengendpos = c("bottomright", "bottomleft", "topleft", "bottomright", "bottomleft", "bottomleft", "bottomright", "bottomright")
usePercent = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)
texts <- c("Baseline", "Bond financed", "Helicopter") #, "Permanent")
# Plot some of the result curve in the R window
par(mfrow = c(3, 2))
for (index in 1:6) {
title <- titles[index]
pos <- lengendpos[index]
if (index != 1) {
pos <- "none"
}
Plotting(result_baseline[[index]], result_bond[[index]], result_helicopter[[index]], result_permanent[[index]], title, texts, pos, usePercent[index])
}
# Print all result curves
for (index in 1:8) {
title <- titles[index]
pos <- lengendpos[index]
filename <- gsub("/", "_", title)
filename = paste0("Images/", filename, ".png")
png(filename, width = 600, height = 300)
Plotting(result_baseline[[index]], result_bond[[index]], result_helicopter[[index]], result_permanent[[index]], title, texts, pos, usePercent[index])
dev.off()
}
}
## End file