Learn R Programming

econocharts

Microeconomic/macroeconomic graphs made with ggplot2

This package allows creating microeconomic charts in R with simple functions. This package inspiration is reconPlots by Andrew Heiss.

THE PACKAGE IS UNDER HEAVY DEVELOPMENT. WORK IN PROGRESS. You can suggest ideas submiting an Issue

TODO

  • Finish documentation
  • Price control
  • Allow drawing custom functions
  • Add graph for budget constraints
  • Fix linecol argument
  • Tax graph
  • Shade producer and consumer surplus
  • Add Edgeworth box

Index

Installation

GitHub

# Install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("R-CoderDotCom/econocharts")

CRAN

The package will be on CRAN as soon as possible

Supply

supply() # Default plot
supply(ncurves = 1,          # Number of supply curves to be plotted
      type = "line",         # Type of the curve
      x = c(2, 4, 5),        # Y-axis values where to create intersections
      linecol = 2,           # Color of the curves
      geom = "label",        # Label type of the intersection points
      geomfill = "pink",     # If geom = "label", is the background color of the label
      main = "Supply curve") # Title of the plot
supply(ncurves = 3, # Three supply curves
       xlab = "X",  # X-axis label
       ylab = "Y",  # Y-axis label
       bg.col = "lightblue") # Background color

Demand

demand(x = 3:6,  # Intersections
      generic = FALSE) # Axis values with the actual numbers
demand(main = "Demand", # Title
       sub = "curve",   # Subtitle
       xlab = "X",      # X-axis label
       ylab = "Y",      # Y-axis label
       names = "D[1]",  # Custom name for the curve
       geomcol = 2)     # Color of the custom name of the curve

Supply and demand

sdcurve() # Default supply and demand plot
# Custom data
supply1 <- data.frame(x = c(1, 9), y = c(1, 9))
supply1

demand1 <- data.frame(x = c(7, 2), y = c(2, 7))
demand1

supply2 <- data.frame(x = c(2, 10), y = c(1, 9))
supply2

demand2 <- data.frame(x = c(8, 2), y = c(2, 8))
demand2

p <- sdcurve(supply1,   # Custom data
             demand1,
             supply2, 
             demand2,
             equilibrium = TRUE, # Calculate the equilibrium
             bg.col = "#fff3cd") # Background color
p + annotate("segment", x = 2.5, xend = 3, y = 6.5, yend = 7,                # Add more layers
             arrow = arrow(length = unit(0.3, "lines")), colour = "grey50")

Indifference curves

indifference() # Default indifference curve
indifference(ncurves = 2,  # Two curves
             x = c(2, 4),  # Intersections
             main = "Indifference curves",
             xlab = "Good X",
             ylab = "Good Y",
             linecol = 2,  # Color of the curves
             pointcol = 2) # Color of the intersection points
p <- indifference(ncurves = 2, x = c(2, 4), main = "Indifference curves", xlab = "Good X", ylab = "Good Y")

int <- bind_rows(curve_intersect(data.frame(x = 1:1000, y = rep(3, nrow(p$curve))), p$curve + 1))

p$p + geom_segment(data = int, aes(x = 0, y = y, xend = x, yend = y), lty = "dotted")  +
      geom_segment(data = int, aes(x = x, y = 0, xend = x, yend = y), lty = "dotted") +
      geom_point(data = int, size = 3)
indifference(ncurves = 2,    # Two curves
             type = "pcom",  # Perfect complements
             main = "Indifference curves",
             sub = "Perfect complements",
             xlab = "Good X",
             ylab = "Good Y",
             bg.col = "#fff3cd", # Background color
             linecol = 1,  # Color of the curve
             pointcol = 2) # Color of the intersection points
indifference(ncurves = 5,     # Five curves
             type = "psubs",  # Perfect substitutes
             main = "Indifference curves",
             sub = "Perfect substitutes",
             xlab = "Good X",
             ylab = "Good Y",
             bg.col = "#fff3cd", # Background color
             linecol = 1) # Color of the curve

Production–possibility frontier

ppf(x = 1:6, # Intersections
   main = "PPF",
   geom = "text",
   generic = TRUE, # Generic axis labels
   xlab = "X",
   ylab = "Y",
   labels = 1:6,
   acol = 3)$p
p <- ppf(x = 4:6, # Intersections
        main = "PPF",
        geom = "text",
        generic = TRUE, # Generic labels
        labels = c("A", "B", "C"), # Custom labels
        xlab = "BIKES",
        ylab = "CARS",
        acol = 3)      # Color of the area

p$p + geom_point(data = data.frame(x = 5, y = 5), size = 3) +
  geom_point(data = data.frame(x = 2, y = 2), size = 3) +
  annotate("segment", x = 3.1, xend = 4.25, y = 5, yend = 5,
           arrow = arrow(length = unit(0.5, "lines")), colour = 3, lwd = 1) +
  annotate("segment", x = 4.25, xend = 4.25, y = 5, yend = 4,
           arrow = arrow(length = unit(0.5, "lines")), colour = 3, lwd = 1)

Laffer curve

laffer(ylab = "T", xlab = "t",
       acol = "lightblue", # Color of the area
       pointcol = 4)       # Color of the maximum point
laffer(xmax = 20, # Modify the curve
       t = c(3, 6, 9), # Intersections
       generic = FALSE,
       ylab = "T",
       xlab = "t",
       acol = "lightblue", # Color of the area
       alpha = 0.6,        # Transparency of the area
       pointcol = 4)       # Color of the maximum point

Copy Link

Version

Version

1.0

License

MIT + file LICENSE

Maintainer

Jos<c3><a9> Carlos Soage Gonz<c3><a1>lez

Last Published

April 29th, 2021

Functions in econocharts (1.0)

econocharts-package

econocharts: Microeconomic Made with 'ggplot2'
supply

Supply curves
demand

demand curves
ppf

Production<U+2013>possibility frontier
sdcurve

Supply and demand chart
curve_intersect

Intersection of two curves
laffer

Laffer curve
indifference

Indifference curves