suppressPackageStartupMessages({
library(ggplot2)
library(grid)
library(tibble)
})
# ----- Parâmetros -----
mc <- 147
q_U <- 64
# Demanda de mercado: P = 339 - Q (Q = q_A + q_U)
# Demanda residual da firma A: P = (339 - q_U) - q_A = 275 - q_A
# RMg residual: 275 - 2*q_A
# Condição: 339 - 2*q_A - q_U - 147 = 0 => q_A* = (192 - q_U)/2
intercept_D <- 339
intercept_Dr <- intercept_D - q_U # 275
p_demanda <- function(Q) intercept_D - Q
p_demanda_r <- function(Q) intercept_Dr - Q
p_mr_r <- function(Q) intercept_Dr - 2 * Q
# Solução
q_A_star <- (192 - q_U) / 2 # 64
P_eq <- p_demanda_r(q_A_star) # 211
# ----- Dados -----
Q_max <- 339
Q_seq <- seq(0, Q_max, length.out = 500)
df <- tibble(
Q = Q_seq,
Demanda = p_demanda(Q_seq),
Demanda_r = p_demanda_r(Q_seq),
MR_r = p_mr_r(Q_seq)
)
# ----- Gráfico -----
ggplot() +
# D — demanda de mercado (azul claro)
geom_line(data = df, aes(x = Q, y = Demanda),
colour = "#64B5F6", linewidth = 1.4) +
# D^r — demanda residual (azul escuro)
geom_line(data = df[df$Demanda_r >= 0, ],
aes(x = Q, y = Demanda_r),
colour = "#1565C0", linewidth = 1.4) +
# RMg^r — receita marginal residual (roxo)
geom_line(data = df[df$MR_r >= 0, ],
aes(x = Q, y = MR_r),
colour = "#7B1FA2", linewidth = 1.4) +
# CMg (vermelho)
geom_segment(aes(x = 0, xend = Q_max, y = mc, yend = mc),
colour = "#D32F2F", linewidth = 1.3) +
# ----- Linhas tracejadas -----
# Vertical q_A* = 64 (do eixo x até P_eq)
annotate("segment", x = q_A_star, xend = q_A_star, y = 0, yend = P_eq,
linetype = "dashed", colour = "black", linewidth = 0.9) +
# Horizontal P = 211 (do eixo y até q_A*)
annotate("segment", x = 0, xend = q_A_star, y = P_eq, yend = P_eq,
linetype = "dashed", colour = "black", linewidth = 0.9) +
# Vertical q_A = 128 (onde D^r cruza CMg: 275 - q = 147 => q = 128)
annotate("segment", x = 128, xend = 128, y = 0, yend = mc,
linetype = "dashed", colour = "black", linewidth = 0.9) +
# Vertical q_A = 137.5 (onde RMg^r = 0: 275 - 2q = 0 => q = 137.5)
annotate("segment", x = 137.5, xend = 137.5, y = 0, yend = p_mr_r(137.5),
linetype = "dashed", colour = "black", linewidth = 0.9) +
# ----- Ponto de equilíbrio -----
annotate("point", x = q_A_star, y = P_eq, size = 4, colour = "black") +
# ----- Seta q_U = 64 -----
annotate("segment",
x = 120, xend = q_A_star + 4,
y = 260, yend = P_eq + 4,
arrow = arrow(length = unit(8, "pt"), type = "closed"),
linewidth = 0.8, colour = "black") +
annotate("text", x = 125, y = 260,
label = "q[U] == 64", parse = TRUE,
size = 4.5, hjust = 0) +
# ----- Rótulos das curvas -----
annotate("text", x = 300, y = p_demanda(300) + 10,
label = "D", colour = "#64B5F6", size = 5, fontface = "bold") +
annotate("text", x = 250, y = p_demanda_r(250) + 10,
label = "D^r", colour = "#1565C0", size = 5, fontface = "bold", parse = TRUE) +
annotate("text", x = 125, y = p_mr_r(125) + 12,
label = "RMg^r", colour = "#7B1FA2", size = 5, fontface = "bold", parse = TRUE, hjust = - 0.4) +
annotate("text", x = 310, y = mc + 12,
label = "CMg", colour = "#D32F2F", size = 5, fontface = "bold") +
# ----- Eixos com setas -----
annotate("segment", x = 0, xend = Q_max * 1.05, y = 0, yend = 0,
arrow = arrow(length = unit(6, "pt")),
linewidth = 0.7, colour = "grey40") +
annotate("segment", x = 0, xend = 0, y = 0, yend = 350,
arrow = arrow(length = unit(6, "pt")),
linewidth = 0.7, colour = "grey40") +
# ----- Escalas -----
scale_x_continuous(
limits = c(0, Q_max * 1.08),
breaks = c(64, 128, 137.5, 275, 339),
labels = c("64", "128", "137,5", "275", "339"),
expand = c(0, 0)
) +
scale_y_continuous(
limits = c(0, 355),
breaks = c(147, 211, 275, 339),
labels = c("147", "211", "275", "339"),
expand = c(0, 0)
) +
labs(
x = expression(bold(q[A] ~ ", milhares de passageiros por trimestre")),
y = "p, $ por passageiro"
) +
theme_minimal(base_size = 13) +
theme(
panel.grid = element_blank(),
axis.title = element_text(face = "bold"),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)
)