-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild CD plot.R
85 lines (59 loc) · 2.65 KB
/
build CD plot.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
75
76
77
78
79
80
81
82
83
84
85
## version 9.2.15.a
#graphing the Cobb Douglas Table
scheme <- data.frame( wealth_color = "#00aaaaff"
, utility_color = "#aa0000ff"
, wealth_thick = 2
, utility_thick = 2
, wealth_style = "solid"
, utility_style = "solid"
, x_star_color = "#000000ff"
, x_star_size = 4
, x_star_style = 8)
plot_cd <- function(table, pallete, add){
require(ggplot2)
if(missing(add)){
add <- FALSE
}
wealth <- as.data.frame( subset(table$data, curve == "wealth") )
utility <- as.data.frame( subset(table$data, curve == "utility") )
names(wealth) <- c("x1", "x2", "curve")
names(utility) <- c("x1", "x2", "curve")
sig_values <- as.data.frame(table$sig_values)
base <- ggplot( data = wealth
, aes( x = x1
,y = x2
)
, add = add
)
wlayer <- base + geom_line( data = wealth
, aes( x = x1
, y = x2)
, color = pallete$wealth_color
, linetype = as.character(pallete$wealth_style)
, size = pallete$wealth_thick
, lineend = "round"
)
labslayer <- wlayer + ggtitle( paste(names(table$data)[1], " vs ", names(table$data)[2]) )+ xlab(names(table$data)[1] ) + ylab(names(table$data)[2])
axislayer <- labslayer + geom_hline() + geom_vline()
ulayer <- axislayer + geom_line(data = utility
, color = pallete$utility_color
, aes( x = x1
, y = x2
)
, linetype = as.character(pallete$utility_style)
, size = pallete$utility_thick
)
starlayer <- ulayer + geom_point(data = sig_values,
aes(x = x1_star,
y = x2_star
)
, size = pallete$x_star_size
, shape = (pallete$x_star_style)
, color = pallete$x_star_color
)
shell <- starlayer + xlim(0, max(sig_values$xintercept*1.1, sig_values$xintercept2*1.1)) + ylim(0, max(sig_values$yintercept*1.1, sig_values$yintercept2*1.1))
return(shell)
}
original_plot <- plot_cd(pallete = scheme
, table = test_set)
original_plot