Ejercicio 3

Suponga que 3 individuos, cuya demanda del bien público viene dada por:

\(p=\frac{1}{i}(200-Q)\), donde \(i=3,5,7\)

  1. Determine la demanda del bien público

Por lo que la demanda final total es:

\(p=\sum_{i=3,5,7}^{}=\frac{1}{i}(200-Q)= (\frac{1}{3}+\frac{1}{5}+\frac{1}{7})(200-Q)=\frac{71}{5}\)

por lo tanto:

\(p=\frac{71}{5}(200−Q), 0 ≤ Q ≤ 200\)

#libreria
library(ggplot2)
library(tidyr)

#vector Q de 0 a 200 de 10 en 10
Q <- seq(0, 200, by = 10)

#funciones
P3 <- (1/3) * (200 - Q)
P5 <- (1/5) * (200 - Q)
P7 <- (1/7) * (200 - Q)
PT <- (71/105) * (200 - Q) #demanda total

#tabla alargada
tabla_demandas <- data.frame(
  Cantidad_Q = Q,
  Precio_i3 = round(P3, 2),
  Precio_i5 = round(P5, 2),
  Precio_i7 = round(P7, 2),
  Precio_Total = round(PT, 2)
)

#print 
print("Tabla de Demandas:")
## [1] "Tabla de Demandas:"
print(tabla_demandas)
##    Cantidad_Q Precio_i3 Precio_i5 Precio_i7 Precio_Total
## 1           0     66.67        40     28.57       135.24
## 2          10     63.33        38     27.14       128.48
## 3          20     60.00        36     25.71       121.71
## 4          30     56.67        34     24.29       114.95
## 5          40     53.33        32     22.86       108.19
## 6          50     50.00        30     21.43       101.43
## 7          60     46.67        28     20.00        94.67
## 8          70     43.33        26     18.57        87.90
## 9          80     40.00        24     17.14        81.14
## 10         90     36.67        22     15.71        74.38
## 11        100     33.33        20     14.29        67.62
## 12        110     30.00        18     12.86        60.86
## 13        120     26.67        16     11.43        54.10
## 14        130     23.33        14     10.00        47.33
## 15        140     20.00        12      8.57        40.57
## 16        150     16.67        10      7.14        33.81
## 17        160     13.33         8      5.71        27.05
## 18        170     10.00         6      4.29        20.29
## 19        180      6.67         4      2.86        13.52
## 20        190      3.33         2      1.43         6.76
## 21        200      0.00         0      0.00         0.00
  1. Grafique las demandas individuales y la demanda total
#datos del grafico
datos_grafico <- pivot_longer(tabla_demandas, 
                              cols = starts_with("Precio"), 
                              names_to = "Individuo", 
                              values_to = "Precio")
#grafico
grafico <- ggplot(datos_grafico, aes(x = Cantidad_Q, y = Precio, color = Individuo, linetype = Individuo)) +
  geom_line(size = 1) +
  scale_color_manual(
    values = c("Precio_i3" = "blue", "Precio_i5" = "green4", "Precio_i7" = "orange", "Precio_Total" = "red"),
    labels = c("Individuo 3", "Individuo 5", "Individuo 7", "Demanda Total")
  ) +
  scale_linetype_manual(
    values = c("Precio_i3" = "solid", "Precio_i5" = "solid", "Precio_i7" = "solid", "Precio_Total" = "dashed"),
    labels = c("Individuo 3", "Individuo 5", "Individuo 7", "Demanda Total")
  ) +
  labs(
    title = "Demanda del Bien Publico",
    subtitle = "Suma vertical de las disposiciones a pagar individuales",
    x = "Cantidad del Bien Público (Q)",
    y = "Precio (P)"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold"),
    plot.subtitle = element_text(hjust = 0.5),
    legend.title = element_blank(),
    legend.position = "bottom"
  ) +
  scale_x_continuous(breaks = seq(0, 200, by = 20)) +
  scale_y_continuous(breaks = seq(0, 140, by = 20))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
#print
print(grafico)