suppressPackageStartupMessages({
library(ggplot2)
library(dplyr)
library(patchwork)
library(latex2exp)
})
# Demanda linear: Q = 12 - p => p = 12 - Q
# Receita total: R(p) = p * (12 - p) = 12p - p^2
q_seq <- seq(0, 12, by = 0.1)
p_seq <- 12 - q_seq # p no eixo y
dados_d <- data.frame(q = q_seq, p = p_seq)
# Painel superior: curva de demanda com regiões
p_demand <- ggplot() +
# Região inelástica (p < 6, q > 6)
annotate("rect",
xmin = 6, xmax = 12, ymin = 0, ymax = 6,
fill = "#cce5ff", alpha = 0.45
) +
# Região elástica (p > 6, q < 6)
annotate("rect",
xmin = 0, xmax = 6, ymin = 6, ymax = 12,
fill = "#ffcccc", alpha = 0.45
) +
geom_line(
data = dados_d,
aes(x = q, y = p),
color = "steelblue",
linewidth = 1.4
) +
geom_point(aes(x = 6, y = 6), color = "darkgreen", size = 4) +
geom_segment(
aes(x = 6, xend = 6, y = 0, yend = 6),
linetype = "dashed", color = "gray50", linewidth = 0.8
) +
geom_segment(
aes(x = 0, xend = 6, y = 6, yend = 6),
linetype = "dashed", color = "gray50", linewidth = 0.8
) +
annotate("label", x = 6 + 1.0, y = 7,
label = "\u03B5 = -1 (ponto m\u00E9dio)",
fill = "white", label.size = 0.3,
size = 4, color = "darkgreen", fontface = "bold"
) +
annotate("label", x = 3, y = 10.5,
label = "El\u00E1stica (|\u03B5| > 1)",
fill = "#ffcccc", label.size = 0.3,
size = 4, color = "darkred"
) +
annotate("label", x = 11, y = 3,
label = "Inel\u00E1stica (|\u03B5| < 1)",
fill = "#cce5ff", label.size = 0.3,
size = 4, color = "darkblue"
) +
annotate("label", x = 10.5, y = 8,
label = TeX(r"(D: $Q = 12 - p$)"),
fill = "white", label.size = 0.3,
size = 5.5, color = "steelblue"
) +
scale_x_continuous(
breaks = seq(0, 12, by = 2),
limits = c(0, 13),
expand = c(0, 0)
) +
scale_y_continuous(
breaks = seq(0, 12, by = 2),
limits = c(0, 13),
expand = c(0, 0)
) +
labs(
title = TeX(r"(Curva de demanda: $Q = 12 - p$)"),
x = TeX(r"(Quantidade ($Q$))"),
y = TeX(r"(Preço ($p$))")
) +
theme_minimal() +
theme(
plot.title = element_text(size = 18, face = "bold"),
plot.subtitle = element_text(size = 14),
axis.line = element_line(color = "black", linewidth = 0.5),
axis.title = element_text(size = 16, face = "bold"),
axis.text = element_text(size = 14),
legend.text = element_text(size = 13),
legend.position = "bottom"
)
# Painel inferior: receita total R(p) = p*(12-p)
p_vals <- seq(0, 12, by = 0.1)
r_vals <- p_vals * (12 - p_vals)
dados_r <- data.frame(p = p_vals, r = r_vals)
p_revenue <- ggplot() +
geom_line(
data = dados_r,
aes(x = p, y = r),
color = "darkorange",
linewidth = 1.4
) +
geom_point(aes(x = 6, y = 36), color = "darkgreen", size = 4) +
geom_segment(
aes(x = 6, xend = 6, y = 0, yend = 36),
linetype = "dashed", color = "gray50", linewidth = 0.8
) +
annotate("label", x = 6 + 1.5, y = 36,
label = "RT m\u00E1x = 36 (p = 6, \u03B5 = -1)",
fill = "white", label.size = 0.3,
size = 4, color = "darkgreen", fontface = "bold"
) +
annotate("label", x = 1.5, y = 23,
label = "RT sobe\ncom p\n(inelástica)",
fill = "#cce5ff", label.size = 0.3,
size = 3.8, color = "darkblue"
) +
annotate("label", x = 10.5, y = 23,
label = "RT cai\ncom p\n(elástica)",
fill = "#ffcccc", label.size = 0.3,
size = 3.8, color = "darkred"
) +
scale_x_continuous(
breaks = seq(0, 12, by = 2),
limits = c(0, 13),
expand = c(0, 0)
) +
scale_y_continuous(
breaks = seq(0, 36, by = 6),
limits = c(0, 40),
expand = c(0, 0)
) +
labs(
title = TeX(r"(Receita total: $R(p) = p \cdot (12 - p)$)"),
x = TeX(r"(Preço ($p$))"),
y = TeX(r"(Receita total ($R$))")
) +
theme_minimal() +
theme(
plot.title = element_text(size = 18, face = "bold"),
plot.subtitle = element_text(size = 14),
axis.line = element_line(color = "black", linewidth = 0.5),
axis.title = element_text(size = 16, face = "bold"),
axis.text = element_text(size = 14),
legend.text = element_text(size = 13),
legend.position = "bottom"
)
p_demand / p_revenue