suppressPackageStartupMessages({
library(ggplot2)
library(latex2exp)
})
# PPF: y = 13.5 - 0.5x^2
x_ppf <- seq(0, 5.2, length.out = 300)
y_ppf <- 13.5 - 0.5 * x_ppf^2
# Equilíbrio
x_eq <- 3
y_eq <- 9
U_eq <- 27
# Curva de indiferença U = xy = 27
x_ic <- seq(1.5, 9.5, length.out = 300)
y_ic <- U_eq / x_ic
# Isolucro: y = 18 - 3x
x_iso <- seq(0.5, 6, length.out = 300)
y_iso <- 18 - 3 * x_iso
# Labels TeX para legenda
lab_ppf <- TeX("PPF: $y = 13.5 - 0.5x^2$")
lab_ic <- TeX("Indiferença: $U = xy = 27$")
lab_iso <- TeX("Isolucro: $y = 18 - 3x$")
# Dados com aes para legenda
dados <- dplyr::bind_rows(
tibble::tibble(x = x_ppf, y = y_ppf, tipo = "ppf"),
tibble::tibble(x = x_ic, y = y_ic, tipo = "ic"),
tibble::tibble(x = x_iso, y = y_iso, tipo = "iso")
)
ggplot2::ggplot(dados, ggplot2::aes(x = x, y = y, color = tipo, linetype = tipo)) +
ggplot2::geom_line(linewidth = 1) +
# Eixos
ggplot2::geom_hline(yintercept = 0, linewidth = 0.5, color = "black") +
ggplot2::geom_vline(xintercept = 0, linewidth = 0.5, color = "black") +
# Projeções do equilíbrio
ggplot2::geom_segment(
ggplot2::aes(x = x_eq, y = 0, xend = x_eq, yend = y_eq),
linetype = "dashed", color = "gray60", linewidth = 0.4, inherit.aes = FALSE
) +
ggplot2::geom_segment(
ggplot2::aes(x = 0, y = y_eq, xend = x_eq, yend = y_eq),
linetype = "dashed", color = "gray60", linewidth = 0.4, inherit.aes = FALSE
) +
# Ponto de equilíbrio
ggplot2::geom_point(
data = tibble::tibble(x = x_eq, y = y_eq),
ggplot2::aes(x = x, y = y),
color = "red", size = 4, shape = 16, inherit.aes = FALSE
) +
# Rótulos nas curvas
ggplot2::annotate(
"text", x = x_eq + 0.4, y = y_eq + 1.2,
label = TeX("$E^* = (3,\\, 9)$", output = "character"),
color = "red", fontface = "bold", size = 4.5, parse = TRUE
) +
ggplot2::annotate(
"text", x = 1, y = 11.5,
label = TeX("$y = 13.5 - 0.5x^2$", output = "character"),
color = "steelblue", size = 3.5, parse = TRUE
) +
ggplot2::annotate(
"text", x = 8, y = 4,
label = TeX("$U = xy = 27$", output = "character"),
color = "darkgreen", size = 3.5, parse = TRUE
) +
ggplot2::annotate(
"text", x = 5.5, y = 3.5,
label = TeX("$y = 18 - 3x$", output = "character"),
color = "darkorange3", size = 3.5, parse = TRUE
) +
ggplot2::annotate(
"text", x = 7, y = 2,
label = TeX("$TMS = TMT = \\frac{P_x}{P_y} = 3$", output = "character"),
color = "gray30", size = 4, parse = TRUE
) +
# Intercepto isolucro
ggplot2::geom_point(
data = tibble::tibble(x = 0, y = 18),
ggplot2::aes(x = x, y = y),
color = "darkorange3", size = 2.5, shape = 17, inherit.aes = FALSE
) +
ggplot2::annotate(
"text", x = 0.8, y = 18.8,
label = TeX("$\\Pi^* = 18$", output = "character"),
color = "darkorange3", size = 3.5, parse = TRUE
) +
# Escalas com legenda
ggplot2::scale_color_manual(
values = c("ppf" = "steelblue", "ic" = "darkgreen", "iso" = "darkorange3"),
labels = c("ppf" = lab_ppf, "ic" = lab_ic, "iso" = lab_iso)
) +
ggplot2::scale_linetype_manual(
values = c("ppf" = "solid", "ic" = "solid", "iso" = "dotted"),
labels = c("ppf" = lab_ppf, "ic" = lab_ic, "iso" = lab_iso)
) +
ggplot2::scale_x_continuous(
limits = c(0, 10), expand = c(0, 0),
breaks = seq(0, 10, by = 1)
) +
ggplot2::scale_y_continuous(
limits = c(0, 20), expand = c(0, 0),
breaks = seq(0, 20, by = 2)
) +
ggplot2::labs(
title = "Exemplo 1: Equilíbrio Geral com Produção",
subtitle = "PPF, curva de indiferença e isolucro tangentes no equilíbrio",
x = TeX("Bem $x$"), y = TeX("Bem $y$"),
color = NULL, linetype = NULL
) +
ggplot2::theme_minimal() +
ggplot2::theme(
legend.position = c(0.78, 0.88),
legend.background = ggplot2::element_rect(fill = "white", color = "gray80", linewidth = 0.3),
legend.text = ggplot2::element_text(size = 9),
legend.key.width = ggplot2::unit(1.5, "cm"),
plot.title = ggplot2::element_text(size = 13, face = "bold"),
axis.title = ggplot2::element_text(size = 11),
axis.line = ggplot2::element_line(color = "black", linewidth = 0.3),
panel.grid.minor = ggplot2::element_blank()
)