R-CoderDotCom / econocharts

Microeconomics/macroeconomics charts in ggplot2
https://r-coder.com/economics-charts-r/
Other
248 stars 58 forks source link

Edgeworth Box? #2

Open emraher opened 3 years ago

emraher commented 3 years ago

I'm not sure if this is possible but I think it's closely related to https://github.com/R-CoderDotCom/econocharts/issues/1#issue-743830157.

Having Edgeworth will be nice. Thanks for the package and your efforts.

R-CoderDotCom commented 3 years ago

Hey there! I also though about creating the Edgeworth box but I think it is difficult to generalize. I mean, I think it is easy to create an Edgeworth box with ggplot2, but to create a function to satisfy all the user needs.

As an example, one could do something like the following:

curve_A <- data.frame(Hmisc::bezier(c(0.9, 3, 9),
                                  c(9, 3, 0.9)))

curve_B <- data.frame(Hmisc::bezier(c(0.1, 4.9, 6),
                                    c(6, 4.9, 0.1)))

p <- ggplot(mapping = aes(x = x, y = y))

for(i in -2:2){
  p <- p + geom_line(data = curve_A + i, lwd = 2)
}

for(i in -2:2){
  p <- p + geom_line(data = curve_B + i, lwd = 2, color = 2)
}

p <- p + theme_classic() + theme(panel.background = element_rect(colour = "black", size = 1))
p

imagen

However, the main problem is that I had to fine tune the values of curve_B. Maybe there is a better way to define the curves...

I will add it to the enhancements list of the Readme.md and I will give it a try when possible. Thanks for your suggestion!

bangecon commented 2 years ago

Hi. I created a function (and a shiny app) that does some cool things with an Edgeworth Box, assuming a Cobb-Douglass utility function. https://github.com/bangecon/EdgeworthBox Comments Welcome