# Datos de entrada: límites de edad y tasas en cada intervalo
edad_lim <- c(15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70)

# Tasas de ocupación para Hombres (en porcentaje)
tasa_hombres <- c(40.9, 76.1, 86.6, 91.8, 93.1, 92.3, 93.6, 92.1, 84.3, 78.6, 62.9)

# Tasas de ocupación para Mujeres (en porcentaje)
tasa_mujeres <- c(21.9, 52.7, 63.3, 66.6, 68.2, 71.9, 69.7, 67.2, 58.8, 46.7, 36.3)
# Repetimos el último valor para cubrir el extremo 70 (extrapolación en el último intervalo)
tasa_hombres_ext <- c(tasa_hombres, tail(tasa_hombres, 1))
tasa_mujeres_ext <- c(tasa_mujeres, tail(tasa_mujeres, 1))

# Vector de edades simples para las cuales deseamos la interpolación
edad_out <- 15:69
# Interpolación lineal para Hombres
interp_hombres <- approx(x = edad_lim,
                         y = tasa_hombres_ext,
                         xout = edad_out,
                         method = "linear",
                         rule = 2)$y
# Interpolación lineal para Mujeres
interp_mujeres <- approx(x = edad_lim,
                         y = tasa_mujeres_ext,
                         xout = edad_out,
                         method = "linear",
                         rule = 2)$y
# Unimos los resultados en un data.frame
tasa_interpolada <- data.frame(
  Edad    = edad_out,
  Hombres = interp_hombres,
  Mujeres = interp_mujeres
)
# Visualizamos la tabla final
print(tasa_interpolada)
##    Edad Hombres Mujeres
## 1    15   40.90   21.90
## 2    16   47.94   28.06
## 3    17   54.98   34.22
## 4    18   62.02   40.38
## 5    19   69.06   46.54
## 6    20   76.10   52.70
## 7    21   78.20   54.82
## 8    22   80.30   56.94
## 9    23   82.40   59.06
## 10   24   84.50   61.18
## 11   25   86.60   63.30
## 12   26   87.64   63.96
## 13   27   88.68   64.62
## 14   28   89.72   65.28
## 15   29   90.76   65.94
## 16   30   91.80   66.60
## 17   31   92.06   66.92
## 18   32   92.32   67.24
## 19   33   92.58   67.56
## 20   34   92.84   67.88
## 21   35   93.10   68.20
## 22   36   92.94   68.94
## 23   37   92.78   69.68
## 24   38   92.62   70.42
## 25   39   92.46   71.16
## 26   40   92.30   71.90
## 27   41   92.56   71.46
## 28   42   92.82   71.02
## 29   43   93.08   70.58
## 30   44   93.34   70.14
## 31   45   93.60   69.70
## 32   46   93.30   69.20
## 33   47   93.00   68.70
## 34   48   92.70   68.20
## 35   49   92.40   67.70
## 36   50   92.10   67.20
## 37   51   90.54   65.52
## 38   52   88.98   63.84
## 39   53   87.42   62.16
## 40   54   85.86   60.48
## 41   55   84.30   58.80
## 42   56   83.16   56.38
## 43   57   82.02   53.96
## 44   58   80.88   51.54
## 45   59   79.74   49.12
## 46   60   78.60   46.70
## 47   61   75.46   44.62
## 48   62   72.32   42.54
## 49   63   69.18   40.46
## 50   64   66.04   38.38
## 51   65   62.90   36.30
## 52   66   62.90   36.30
## 53   67   62.90   36.30
## 54   68   62.90   36.30
## 55   69   62.90   36.30
# Graficar Hombres en azul
plot(
  x    = tasa_interpolada$Edad,
  y    = tasa_interpolada$Hombres,
  type = "o",          # "o": dibuja línea + marcadores
  pch  = 16,           # Marcador sólido
  col  = "blue",
  lty  = 1,            # Línea continua
  ylim = c(0, 100),    # Ajustar a 0-100 si las tasas van en ese rango
  xlab = "Edad",
  ylab = "Tasa de Ocupación (%)",
  main = "Tasas de Ocupación por Edad y Sexo"
)

# Añadir la serie de Mujeres en rojo
lines(
  x    = tasa_interpolada$Edad,
  y    = tasa_interpolada$Mujeres,
  type = "o",
  pch  = 17,           # Otro marcador
  col  = "red",
  lty  = 1
)

# Agregar leyenda
legend(
  "bottomright",
  legend = c("Hombres", "Mujeres"),
  col    = c("blue", "red"),
  pch    = c(16, 17),
  lty    = 1,
  bty    = "n"
)