Modulo 1 - Encuesta Origen-Destino Cali

Áreas de la estadística Espacial y conceptos de cartografía

A continuación, se expone el ejercicio de análisis de la encuesta de origen y destino en Cali. El objetivo principal es crear una serie de mapas que reflejen los patrones de movimiento de las personas dentro de la ciudad. Sin embargo, antes de adentrarnos en el análisis específico, es necesario preparar y organizar los datos adecuadamente. Por esta razón, el taller se estructura en las siguientes etapas:

##1. Pasos previos: Carga de librerías y archivos necesarios.

Comenzamos el ejercicio con la carga de librerias y archivos necesarios para el desarrollo del caso en el cual se incluyen archivos xslx y shapes

#Carga de Librerias
require(raster)
## Cargando paquete requerido: raster
## Cargando paquete requerido: sp
require(leaflet)
## Cargando paquete requerido: leaflet
require(sf)
## Cargando paquete requerido: sf
## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE

##Carga de mapa de las comunas

#Carga de archivos
comunas <- shapefile("C:/Users/karenca/Documents/Casos/cali/Comunas.shp")
comunas
## class       : SpatialPolygonsDataFrame 
## features    : 22 
## extent      : 1053868, 1068492, 860190.2, 879441.5  (xmin, xmax, ymin, ymax)
## crs         : +proj=tmerc +lat_0=3.441883333 +lon_0=-76.5205625 +k=1 +x_0=1061900.18 +y_0=872364.63 +a=6379137 +rf=298.257222101 +units=m +no_defs 
## variables   : 4
## names       : OBJECTID, gid, comuna,   nombre 
## min values  :        1,  89,      1, Comuna 1 
## max values  :       22, 110,     22, Comuna 9
plot(comunas)

Carga de archivo xlsx

Este archivo contiene la información recolectada en la encuesta para poder realizar el analisis de movimiento dentro de los mapas

#Carga de archivo excel 
require(readxl)
## Cargando paquete requerido: readxl
data= read_excel("C:/Users/karenca/OneDrive - HDI Seguros/Documentos/Visualizacion de datos/Casos/EncuestaOrigenDestino.xlsx")
## Warning: Coercing numeric to date in A2058 / R2058C1
## Warning: Coercing numeric to date in F2058 / R2058C6
## Warning: Coercing numeric to date in A2059 / R2059C1
## Warning: Coercing numeric to date in F2059 / R2059C6
## Warning: Coercing numeric to date in A2060 / R2060C1
## Warning: Coercing numeric to date in F2060 / R2060C6
## Warning: Coercing numeric to date in A2061 / R2061C1
## Warning: Coercing numeric to date in F2061 / R2061C6
## Warning: Coercing numeric to date in A2062 / R2062C1
## Warning: Coercing numeric to date in F2062 / R2062C6
## Warning: Coercing numeric to date in A2063 / R2063C1
## Warning: Coercing numeric to date in F2063 / R2063C6
## Warning: Coercing numeric to date in A2064 / R2064C1
## Warning: Coercing numeric to date in F2064 / R2064C6
## Warning: Coercing numeric to date in A2065 / R2065C1
## Warning: Coercing numeric to date in F2065 / R2065C6
## Warning: Coercing numeric to date in A2066 / R2066C1
## Warning: Coercing numeric to date in F2066 / R2066C6
## Warning: Coercing numeric to date in A2067 / R2067C1
## Warning: Coercing numeric to date in F2067 / R2067C6
## Warning: Coercing numeric to date in A2068 / R2068C1
## Warning: Coercing numeric to date in F2068 / R2068C6
## Warning: Coercing numeric to date in A2069 / R2069C1
## Warning: Coercing numeric to date in F2069 / R2069C6
## Warning: Coercing numeric to date in A2070 / R2070C1
## Warning: Coercing numeric to date in F2070 / R2070C6
## Warning: Coercing numeric to date in A2071 / R2071C1
## Warning: Coercing numeric to date in F2071 / R2071C6
## Warning: Coercing numeric to date in A2072 / R2072C1
## Warning: Coercing numeric to date in F2072 / R2072C6
## Warning: Coercing numeric to date in A2073 / R2073C1
## Warning: Coercing numeric to date in F2073 / R2073C6
## Warning: Coercing numeric to date in A2074 / R2074C1
## Warning: Coercing numeric to date in F2074 / R2074C6
## Warning: Coercing numeric to date in A2075 / R2075C1
## Warning: Coercing numeric to date in F2075 / R2075C6
## Warning: Coercing numeric to date in A2076 / R2076C1
## Warning: Coercing numeric to date in F2076 / R2076C6
## Warning: Coercing numeric to date in A2077 / R2077C1
## Warning: Coercing numeric to date in F2077 / R2077C6
## Warning: Coercing numeric to date in A2078 / R2078C1
## Warning: Coercing numeric to date in F2078 / R2078C6
## Warning: Coercing numeric to date in A2079 / R2079C1
## Warning: Coercing numeric to date in F2079 / R2079C6
## Warning: Coercing numeric to date in A2080 / R2080C1
## Warning: Coercing numeric to date in F2080 / R2080C6
## Warning: Coercing numeric to date in A2081 / R2081C1
## Warning: Coercing numeric to date in F2081 / R2081C6
## Warning: Coercing numeric to date in A2082 / R2082C1
## Warning: Coercing numeric to date in F2082 / R2082C6
## Warning: Coercing numeric to date in A2083 / R2083C1
## Warning: Coercing numeric to date in F2083 / R2083C6
## Warning: Coercing numeric to date in A2084 / R2084C1
## Warning: Coercing numeric to date in F2084 / R2084C6
## Warning: Coercing numeric to date in A2085 / R2085C1
## Warning: Coercing numeric to date in F2085 / R2085C6
## Warning: Coercing numeric to date in A2086 / R2086C1
## Warning: Coercing numeric to date in F2086 / R2086C6
## Warning: Coercing numeric to date in A2087 / R2087C1
## Warning: Coercing numeric to date in F2087 / R2087C6
## Warning: Coercing numeric to date in A2088 / R2088C1
## Warning: Coercing numeric to date in F2088 / R2088C6
## Warning: Coercing numeric to date in A2089 / R2089C1
## Warning: Coercing numeric to date in F2089 / R2089C6
## Warning: Coercing numeric to date in A2090 / R2090C1
## Warning: Coercing numeric to date in F2090 / R2090C6
## Warning: Coercing numeric to date in A2091 / R2091C1
## Warning: Coercing numeric to date in F2091 / R2091C6
## Warning: Coercing numeric to date in A2092 / R2092C1
## Warning: Coercing numeric to date in F2092 / R2092C6
## Warning: Coercing numeric to date in A2093 / R2093C1
## Warning: Coercing numeric to date in F2093 / R2093C6
## Warning: Coercing numeric to date in A2094 / R2094C1
## Warning: Coercing numeric to date in F2094 / R2094C6
## Warning: Coercing numeric to date in A2095 / R2095C1
## Warning: Coercing numeric to date in F2095 / R2095C6
## Warning: Coercing numeric to date in A2096 / R2096C1
## Warning: Coercing numeric to date in F2096 / R2096C6
## Warning: Coercing numeric to date in A2097 / R2097C1
## Warning: Coercing numeric to date in F2097 / R2097C6
## Warning: Coercing numeric to date in A2098 / R2098C1
## Warning: Coercing numeric to date in F2098 / R2098C6
## Warning: Coercing numeric to date in A2099 / R2099C1
## Warning: Coercing numeric to date in F2099 / R2099C6
## Warning: Coercing numeric to date in A2100 / R2100C1
## Warning: Coercing numeric to date in F2100 / R2100C6
## Warning: Coercing numeric to date in A2101 / R2101C1
## Warning: Coercing numeric to date in F2101 / R2101C6
## Warning: Coercing numeric to date in A2102 / R2102C1
## Warning: Coercing numeric to date in F2102 / R2102C6
## Warning: Coercing numeric to date in A2103 / R2103C1
## Warning: Coercing numeric to date in F2103 / R2103C6
## Warning: Coercing numeric to date in A2104 / R2104C1
## Warning: Coercing numeric to date in F2104 / R2104C6
## Warning: Coercing numeric to date in A2105 / R2105C1
## Warning: Coercing numeric to date in F2105 / R2105C6
## Warning: Coercing numeric to date in A2106 / R2106C1
## Warning: Coercing numeric to date in F2106 / R2106C6
## Warning: Coercing numeric to date in A2107 / R2107C1
## Warning: Coercing numeric to date in F2107 / R2107C6
## Warning: Coercing numeric to date in A2108 / R2108C1
## Warning: Coercing numeric to date in F2108 / R2108C6
## Warning: Coercing numeric to date in A2109 / R2109C1
## Warning: Coercing numeric to date in F2109 / R2109C6
## Warning: Coercing numeric to date in A2110 / R2110C1
## Warning: Coercing numeric to date in F2110 / R2110C6
## Warning: Coercing numeric to date in A2111 / R2111C1
## Warning: Coercing numeric to date in F2111 / R2111C6
## Warning: Coercing numeric to date in A2112 / R2112C1
## Warning: Coercing numeric to date in F2112 / R2112C6
## Warning: Coercing numeric to date in A2113 / R2113C1
## Warning: Coercing numeric to date in F2113 / R2113C6
## Warning: Coercing numeric to date in A2114 / R2114C1
## Warning: Coercing numeric to date in F2114 / R2114C6
## Warning: Coercing numeric to date in A2115 / R2115C1
## Warning: Coercing numeric to date in F2115 / R2115C6
## Warning: Coercing numeric to date in A2116 / R2116C1
## Warning: Coercing numeric to date in F2116 / R2116C6
## Warning: Coercing numeric to date in A2117 / R2117C1
## Warning: Coercing numeric to date in F2117 / R2117C6
## Warning: Coercing numeric to date in A2118 / R2118C1
## Warning: Coercing numeric to date in F2118 / R2118C6
## Warning: Coercing numeric to date in A2119 / R2119C1
## Warning: Coercing numeric to date in F2119 / R2119C6
## Warning: Coercing numeric to date in A2120 / R2120C1
## Warning: Coercing numeric to date in F2120 / R2120C6
## Warning: Coercing numeric to date in A2121 / R2121C1
## Warning: Coercing numeric to date in F2121 / R2121C6
## Warning: Coercing numeric to date in A2122 / R2122C1
## Warning: Coercing numeric to date in F2122 / R2122C6
## Warning: Coercing numeric to date in A2123 / R2123C1
## Warning: Coercing numeric to date in F2123 / R2123C6
## Warning: Coercing numeric to date in A2124 / R2124C1
## Warning: Coercing numeric to date in F2124 / R2124C6
## Warning: Coercing numeric to date in A2125 / R2125C1
## Warning: Coercing numeric to date in F2125 / R2125C6
## Warning: Coercing numeric to date in A2126 / R2126C1
## Warning: Coercing numeric to date in F2126 / R2126C6
## Warning: Coercing numeric to date in A2127 / R2127C1
## Warning: Coercing numeric to date in F2127 / R2127C6
## Warning: Coercing numeric to date in A2128 / R2128C1
## Warning: Coercing numeric to date in F2128 / R2128C6
## Warning: Coercing numeric to date in A2129 / R2129C1
## Warning: Coercing numeric to date in F2129 / R2129C6
## Warning: Coercing numeric to date in A2130 / R2130C1
## Warning: Coercing numeric to date in F2130 / R2130C6
## Warning: Coercing numeric to date in A2131 / R2131C1
## Warning: Coercing numeric to date in F2131 / R2131C6
## Warning: Coercing numeric to date in A2132 / R2132C1
## Warning: Coercing numeric to date in F2132 / R2132C6
## Warning: Coercing numeric to date in A2133 / R2133C1
## Warning: Coercing numeric to date in F2133 / R2133C6
## Warning: Coercing numeric to date in A2134 / R2134C1
## Warning: Coercing numeric to date in F2134 / R2134C6
## Warning: Coercing numeric to date in A2135 / R2135C1
## Warning: Coercing numeric to date in F2135 / R2135C6
## Warning: Coercing numeric to date in A2136 / R2136C1
## Warning: Coercing numeric to date in F2136 / R2136C6
## Warning: Coercing numeric to date in A2137 / R2137C1
## Warning: Coercing numeric to date in F2137 / R2137C6
## Warning: Coercing numeric to date in A2138 / R2138C1
## Warning: Coercing numeric to date in F2138 / R2138C6
## Warning: Coercing text to numeric in J2333 / R2333C10: '1'
## Warning: Coercing text to numeric in J2334 / R2334C10: '6'
## Warning: Coercing text to numeric in J2335 / R2335C10: '11'
## Warning: Coercing text to numeric in J2336 / R2336C10: '6'
## Warning: Coercing text to numeric in J2337 / R2337C10: '6'
## Warning: Coercing text to numeric in J2338 / R2338C10: '6'
## Warning: Coercing text to numeric in J2339 / R2339C10: '6'
## Warning: Expecting logical in X3860 / R3860C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X4164 / R4164C24: got 'GRUA'
## Warning: Expecting logical in Q6623 / R6623C17: got 'BICICLETA'
## Warning: Expecting logical in X6758 / R6758C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X6900 / R6900C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X7914 / R7914C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X11168 / R11168C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X11833 / R11833C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X12398 / R12398C24: got 'VAN ESCOLAR'
## Warning: Expecting logical in Q13865 / R13865C17: got 'BUSETA'
## Warning: Expecting logical in X17913 / R17913C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X19592 / R19592C24: got 'MOTO-CARRO'
## Warning: Expecting logical in Q22244 / R22244C17: got 'BICICLETA'
## Warning: Expecting logical in X22329 / R22329C24: got 'BUS ESCOLAR'
## Warning: Expecting logical in X24019 / R24019C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X25200 / R25200C24: got 'CARRETILLA'
## Warning: Coercing text to numeric in N26235 / R26235C14: '3'
## Warning: Coercing text to numeric in J26503 / R26503C10: '6'
## Warning: Coercing text to numeric in J26935 / R26935C10: '7'
## Warning: Coercing text to numeric in J26936 / R26936C10: '6'
## Warning: Coercing text to numeric in J26937 / R26937C10: '6'
## Warning: Coercing text to numeric in J26938 / R26938C10: '1'
## Warning: Coercing text to numeric in J26939 / R26939C10: '1'
## Warning: Coercing text to numeric in J26940 / R26940C10: '6'
## Warning: Coercing text to numeric in J26941 / R26941C10: '1'
## Warning: Coercing text to numeric in J26942 / R26942C10: '6'
## Warning: Coercing text to numeric in J26943 / R26943C10: '6'
## Warning: Coercing text to numeric in J26944 / R26944C10: '1'
## Warning: Coercing text to numeric in J26945 / R26945C10: '1'
## Warning: Coercing text to numeric in J26946 / R26946C10: '1'
## Warning: Coercing text to numeric in J26947 / R26947C10: '6'
## Warning: Coercing text to numeric in J26948 / R26948C10: '8'
## Warning: Coercing text to numeric in J26949 / R26949C10: '6'
## Warning: Coercing text to numeric in J26950 / R26950C10: '1'
## Warning: Coercing text to numeric in J26951 / R26951C10: '7'
## Warning: Coercing text to numeric in J26952 / R26952C10: '6'
## Warning: Coercing text to numeric in J26953 / R26953C10: '6'
## Warning: Coercing text to numeric in J26954 / R26954C10: '6'
## Warning: Coercing text to numeric in J26955 / R26955C10: '6'
## Warning: Coercing text to numeric in J26956 / R26956C10: '6'
## Warning: Coercing text to numeric in J26957 / R26957C10: '6'
## Warning: Coercing text to numeric in J26958 / R26958C10: '6'
## Warning: Coercing text to numeric in J26959 / R26959C10: '6'
## Warning: Coercing text to numeric in J26960 / R26960C10: '6'
## Warning: Coercing text to numeric in J26961 / R26961C10: '6'
## Warning: Coercing text to numeric in J26962 / R26962C10: '6'
## Warning: Coercing text to numeric in J26963 / R26963C10: '6'
## Warning: Coercing text to numeric in J26964 / R26964C10: '6'
## Warning: Coercing text to numeric in J26965 / R26965C10: '1'
## Warning: Coercing text to numeric in J26966 / R26966C10: '1'
## Warning: Coercing text to numeric in J26967 / R26967C10: '1'
## Warning: Coercing text to numeric in J26968 / R26968C10: '1'
## Warning: Coercing text to numeric in J26969 / R26969C10: '1'
## Warning: Coercing text to numeric in J26970 / R26970C10: '1'
## Warning: Coercing text to numeric in J26971 / R26971C10: '6'
## Warning: Coercing text to numeric in J26972 / R26972C10: '6'
## Warning: Coercing text to numeric in J26973 / R26973C10: '6'
## Warning: Coercing text to numeric in J26974 / R26974C10: '6'
## Warning: Coercing text to numeric in J26975 / R26975C10: '1'
## Warning: Coercing text to numeric in J26976 / R26976C10: '1'
## Warning: Coercing text to numeric in J26977 / R26977C10: '1'
## Warning: Coercing text to numeric in J26978 / R26978C10: '6'
## Warning: Coercing text to numeric in J26979 / R26979C10: '6'
## Warning: Coercing text to numeric in J26980 / R26980C10: '6'
## Warning: Coercing text to numeric in J26981 / R26981C10: '6'
## Warning: Coercing text to numeric in J26982 / R26982C10: '6'
## Warning: Coercing text to numeric in J26983 / R26983C10: '1'
## Warning: Coercing text to numeric in J26984 / R26984C10: '1'
## Warning: Coercing text to numeric in J26985 / R26985C10: '1'
## Warning: Coercing text to numeric in J26986 / R26986C10: '6'
## Warning: Coercing text to numeric in J26987 / R26987C10: '6'
## Warning: Coercing text to numeric in J26988 / R26988C10: '6'
## Warning: Coercing text to numeric in J26989 / R26989C10: '6'
## Warning: Coercing text to numeric in J26990 / R26990C10: '1'
## Warning: Coercing text to numeric in J26991 / R26991C10: '6'
## Warning: Coercing text to numeric in J26992 / R26992C10: '1'
## Warning: Coercing text to numeric in J26993 / R26993C10: '6'
## Warning: Coercing text to numeric in J26994 / R26994C10: '6'
## Warning: Coercing text to numeric in J26995 / R26995C10: '6'
## Warning: Coercing text to numeric in J26996 / R26996C10: '6'
## Warning: Coercing text to numeric in J26997 / R26997C10: '11'
## Warning: Coercing text to numeric in J26998 / R26998C10: '6'
## Warning: Coercing text to numeric in J26999 / R26999C10: '1'
## Warning: Coercing text to numeric in J27000 / R27000C10: '6'
## Warning: Coercing text to numeric in J27001 / R27001C10: '1'
## Warning: Coercing text to numeric in J27002 / R27002C10: '6'
## Warning: Coercing text to numeric in J27003 / R27003C10: '11'
## Warning: Coercing text to numeric in J27004 / R27004C10: '6'
## Warning: Coercing text to numeric in J27005 / R27005C10: '6'
## Warning: Coercing text to numeric in J27006 / R27006C10: '6'
## Warning: Coercing text to numeric in J27007 / R27007C10: '6'
## Warning: Coercing text to numeric in J27008 / R27008C10: '6'
## Warning: Coercing text to numeric in J27009 / R27009C10: '2'
## Warning: Coercing text to numeric in J27010 / R27010C10: '6'
## Warning: Coercing text to numeric in J27011 / R27011C10: '6'
## Warning: Coercing text to numeric in J27012 / R27012C10: '11'
## Warning: Coercing text to numeric in J27013 / R27013C10: '6'
## Warning: Coercing text to numeric in J27014 / R27014C10: '1'
## Warning: Coercing text to numeric in J27015 / R27015C10: '6'
## Warning: Coercing text to numeric in J27016 / R27016C10: '6'
## Warning: Coercing text to numeric in J27017 / R27017C10: '6'
## Warning: Coercing text to numeric in J27018 / R27018C10: '6'
## Warning: Coercing text to numeric in J27019 / R27019C10: '6'
## Warning: Coercing text to numeric in J27020 / R27020C10: '6'
## Warning: Coercing text to numeric in J27021 / R27021C10: '11'
## Warning: Coercing text to numeric in J27022 / R27022C10: '6'
## Warning: Coercing text to numeric in J27023 / R27023C10: '4'
## Warning: Coercing text to numeric in J27024 / R27024C10: '6'
## Warning: Coercing text to numeric in J27025 / R27025C10: '2'
## Warning: Coercing text to numeric in J27026 / R27026C10: '2'
## Warning: Coercing text to numeric in J27027 / R27027C10: '11'
## Warning: Coercing text to numeric in J27028 / R27028C10: '2'
## Warning: Coercing text to numeric in J27029 / R27029C10: '2'
## Warning: Coercing text to numeric in J27030 / R27030C10: '2'
## Warning: Expecting logical in X31653 / R31653C24: got 'VOLQUETA'
## Warning: Expecting numeric in J31842 / R31842C10: got 'ANULADO'
## Warning: Coercing numeric to date in A33837 / R33837C1
## Warning: Coercing numeric to date in F33837 / R33837C6
## Warning: Expecting logical in X34736 / R34736C24: got 'MOTO-CARRO'
## Warning: Expecting logical in X35053 / R35053C24: got 'MOTO-CARRO'
## New names:
## • `MUNICIPIO` -> `MUNICIPIO...7`
## • `DEPARTAMENTO / LOCALIDAD / COMUNA / DISTRITO / BARRIO / VEREDA / HITO /
##   DIRECCIÓN` -> `DEPARTAMENTO / LOCALIDAD / COMUNA / DISTRITO / BARRIO / VEREDA
##   / HITO / DIRECCIÓN...8`
## • `MUNICIPIO` -> `MUNICIPIO...11`
## • `DEPARTAMENTO / LOCALIDAD / COMUNA / DISTRITO / BARRIO / VEREDA / HITO /
##   DIRECCIÓN` -> `DEPARTAMENTO / LOCALIDAD / COMUNA / DISTRITO / BARRIO / VEREDA
##   / HITO / DIRECCIÓN...12`
## • `OTRO ¿CUÁL?` -> `OTRO ¿CUÁL?...17`
## • `OTRO ¿CUÁL?` -> `OTRO ¿CUÁL?...24`
head(data)
## # A tibble: 6 × 28
##   FECHA               `ID ESTACIÓN` ESTACIÓN               ACCESO MOVIMIENTO
##   <dttm>                      <dbl> <chr>                  <chr>  <chr>     
## 1 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 2 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 3 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 4 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 5 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 6 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## # ℹ 23 more variables: `Hora de Encuesta` <dttm>, MUNICIPIO...7 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...8` <chr>,
## #   `Codigo Origen_SDG` <chr>, `¿QUE ESTABA HACIENDO EN ESE LUGAR?` <dbl>,
## #   MUNICIPIO...11 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...12` <chr>,
## #   `Codigo Destino_SDG` <chr>, `¿QUE VA HACER A ESE LUGAR?` <dbl>,
## #   `ESTRATO EN SU VIVIENDA` <dbl>, …

2. Preparación y limpieza de datos: Tratamiento y depuración de la información para asegurar su calidad y precisión.

En este paso se realiza el filtro de la información para analisis de los viajes que solamente se realizan al interior de la ciudad de Cali.

fueracali = which(data$`comuna origen`!="Fuera de Cali" & data$`comuna destino`!="Fuera de Cali" & data$`comuna origen`!="0" & data$`comuna destino`!="0")

datoscali=data[fueracali,]
head(datoscali)
## # A tibble: 6 × 28
##   FECHA               `ID ESTACIÓN` ESTACIÓN               ACCESO MOVIMIENTO
##   <dttm>                      <dbl> <chr>                  <chr>  <chr>     
## 1 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 2 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 3 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 4 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 5 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 6 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## # ℹ 23 more variables: `Hora de Encuesta` <dttm>, MUNICIPIO...7 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...8` <chr>,
## #   `Codigo Origen_SDG` <chr>, `¿QUE ESTABA HACIENDO EN ESE LUGAR?` <dbl>,
## #   MUNICIPIO...11 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...12` <chr>,
## #   `Codigo Destino_SDG` <chr>, `¿QUE VA HACER A ESE LUGAR?` <dbl>,
## #   `ESTRATO EN SU VIVIENDA` <dbl>, …
datoscali$comuna_origen <- as.numeric(datoscali$`comuna origen`)
datoscali$comuna_destino <- as.numeric(datoscali$`comuna destino`)
head(datoscali)
## # A tibble: 6 × 30
##   FECHA               `ID ESTACIÓN` ESTACIÓN               ACCESO MOVIMIENTO
##   <dttm>                      <dbl> <chr>                  <chr>  <chr>     
## 1 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 2 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 3 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 4 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 5 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 6 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## # ℹ 25 more variables: `Hora de Encuesta` <dttm>, MUNICIPIO...7 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...8` <chr>,
## #   `Codigo Origen_SDG` <chr>, `¿QUE ESTABA HACIENDO EN ESE LUGAR?` <dbl>,
## #   MUNICIPIO...11 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...12` <chr>,
## #   `Codigo Destino_SDG` <chr>, `¿QUE VA HACER A ESE LUGAR?` <dbl>,
## #   `ESTRATO EN SU VIVIENDA` <dbl>, …
datoscali$latitud_comuna_origen = as.numeric(apply(datoscali["comuna_origen"], 1, function(x)
{
  return(coordinates(comunas)[x,2][1])
}))

datoscali$longitud_comuna_origen = as.numeric(apply(datoscali["comuna_origen"], 1, function(x)
{
  return(coordinates(comunas)[x,1][1])
}))


datoscali$latitud_comuna_destino = as.numeric(apply(datoscali["comuna_destino"], 1, function(x)
{
  return(coordinates(comunas)[x,2][1])
}))

datoscali$longitud_comuna_destino = as.numeric(apply(datoscali["comuna_destino"], 1, function(x)
{
  return(coordinates(comunas)[x,1][1])
}))


head(datoscali)
## # A tibble: 6 × 34
##   FECHA               `ID ESTACIÓN` ESTACIÓN               ACCESO MOVIMIENTO
##   <dttm>                      <dbl> <chr>                  <chr>  <chr>     
## 1 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 2 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 3 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 4 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 5 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## 6 2015-06-01 00:00:00             1 Avenida 6N X Calle 70N NORTE  MOV 1     
## # ℹ 29 more variables: `Hora de Encuesta` <dttm>, MUNICIPIO...7 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...8` <chr>,
## #   `Codigo Origen_SDG` <chr>, `¿QUE ESTABA HACIENDO EN ESE LUGAR?` <dbl>,
## #   MUNICIPIO...11 <chr>,
## #   `DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...12` <chr>,
## #   `Codigo Destino_SDG` <chr>, `¿QUE VA HACER A ESE LUGAR?` <dbl>,
## #   `ESTRATO EN SU VIVIENDA` <dbl>, …

3. Mapas de origen: Elaboración de mapas que muestran los puntos de partida de los desplazamientos.

A continuación se muestran los mapas de puntos de partida de acuerdo a los medios de transporte que indica el ejercicio y posteriormente por cada medio de transporte.

origen=SpatialPointsDataFrame(coords = datoscali[,31:32],
                       data = datoscali,
                       proj4string = crs(comunas)
                       )

origen
## class       : SpatialPointsDataFrame 
## features    : 22151 
## extent      : 862283.3, 877232, 1056762, 1067421  (xmin, xmax, ymin, ymax)
## crs         : +proj=tmerc +lat_0=3.441883333 +lon_0=-76.5205625 +k=1 +x_0=1061900.18 +y_0=872364.63 +a=6379137 +rf=298.257222101 +units=m +no_defs 
## variables   : 34
## names       :      FECHA, ID ESTACIÓN,                         ESTACIÓN, ACCESO, MOVIMIENTO, Hora de Encuesta, MUNICIPIO...7, DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...8, Codigo Origen_SDG, ¿QUE ESTABA HACIENDO EN ESE LUGAR?, MUNICIPIO...11, DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...12, Codigo Destino_SDG, ¿QUE VA HACER A ESE LUGAR?, ESTRATO EN SU VIVIENDA, ... 
## min values  : 1430697600,           1,           Autopista Cali-Jamundí,  NORTE,      MOV 1,      -2209053600,          CALI,                                                                               1 DE MAYO,              1001,                                  1,           CALI,                                                                            1 A N GRANADA,               1001,                          1,                      1, ... 
## max values  : 1433808000,          30, Diagonal 15 X Av. Ciudad de Cali,    SUR,      MOV 4,      -2209030260,       POPAYAN,                                                                         ZUPIANO LLOREDA,               914,                                 77,        POPAYAN,                                                                          ZOOLOGICO OESTE,                914,                         77,                      6, ...
#copia del dataframe de origen

origen1=origen
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(origen1) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna <- table(origen1$comuna_origen)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$origen1 <- conteo_por_comuna[match(comunas$comuna, names(conteo_por_comuna))]
comunas$origen1 <- as.numeric(comunas$origen1)

num_colors <- 9
library(RColorBrewer)
color_paleta_azul <- brewer.pal(num_colors, "PuBuGn")

spplot(comunas,"origen1", col.regions = color_paleta_azul, cuts = 6, main = "Comunas origen para viajes en carro, moto y bicicleta")

## Mapa Origen - Carros

carros=which(origen@data$`TIPO DE VEHÍCULO`==3)
origen2=origen[carros,]

origencarro=origen2
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(origencarro) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna2 <- table(origencarro$comuna_origen)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$origencarro <- conteo_por_comuna2[match(comunas$comuna, names(conteo_por_comuna2))]
comunas$origencarro <- as.numeric(comunas$origencarro)

# Mostrar el resultado en el mapa
spplot(comunas,"origencarro", col.regions = color_paleta_azul, cuts = 6, main = "Comunas origen para viajes en carro")

## Mapa Origen - Bicicleta

bicicletas=which(origen@data$`TIPO DE VEHÍCULO`==1)
origen3=origen[bicicletas,]

origenbicicletas=origen3
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(origenbicicletas) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna3 <- table(origenbicicletas$comuna_origen)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$origenbicicletas <- conteo_por_comuna3[match(comunas$comuna, names(conteo_por_comuna3))]
comunas$origenbicicletas <- as.numeric(comunas$origenbicicletas)

# Mostrar el resultado en el mapa
spplot(comunas,"origenbicicletas", col.regions = color_paleta_azul, cuts = 6, main = "Comunas origen para viajes en bicicleta")

## Mapa Origen - Moto

moto=which(origen@data$`TIPO DE VEHÍCULO`==2)

origen4=origen[moto,]

origenmoto=origen4
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(origenmoto) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna4 <- table(origenmoto$comuna_origen)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$origenmoto <- conteo_por_comuna4[match(comunas$comuna, names(conteo_por_comuna4))]
comunas$origenmoto <- as.numeric(comunas$origenmoto)

# Mostrar el resultado
spplot(comunas,"origenmoto",col.regions = color_paleta_azul, cuts = 6, main = "Comunas origen para viajes en moto")

## 4. Mapas de destino: Creación de mapas que indican los lugares de llegada de los movimientos.

En este paso se construyen los mapas que muestran los movimientos de destino en la ciudad de Cali de acuerdo a los origenes de los mapas anteriores por cada medio de transporte propuesto.

destinototal=SpatialPointsDataFrame(coords = datoscali[,33:34],
                       data = datoscali,
                       proj4string = crs(comunas)
                       )

destinototal
## class       : SpatialPointsDataFrame 
## features    : 22151 
## extent      : 862283.3, 877232, 1056762, 1067421  (xmin, xmax, ymin, ymax)
## crs         : +proj=tmerc +lat_0=3.441883333 +lon_0=-76.5205625 +k=1 +x_0=1061900.18 +y_0=872364.63 +a=6379137 +rf=298.257222101 +units=m +no_defs 
## variables   : 34
## names       :      FECHA, ID ESTACIÓN,                         ESTACIÓN, ACCESO, MOVIMIENTO, Hora de Encuesta, MUNICIPIO...7, DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...8, Codigo Origen_SDG, ¿QUE ESTABA HACIENDO EN ESE LUGAR?, MUNICIPIO...11, DEPARTAMENTO / LOCALIDAD  / COMUNA / DISTRITO / BARRIO / VEREDA  / HITO / DIRECCIÓN...12, Codigo Destino_SDG, ¿QUE VA HACER A ESE LUGAR?, ESTRATO EN SU VIVIENDA, ... 
## min values  : 1430697600,           1,           Autopista Cali-Jamundí,  NORTE,      MOV 1,      -2209053600,          CALI,                                                                               1 DE MAYO,              1001,                                  1,           CALI,                                                                            1 A N GRANADA,               1001,                          1,                      1, ... 
## max values  : 1433808000,          30, Diagonal 15 X Av. Ciudad de Cali,    SUR,      MOV 4,      -2209030260,       POPAYAN,                                                                         ZUPIANO LLOREDA,               914,                                 77,        POPAYAN,                                                                          ZOOLOGICO OESTE,                914,                         77,                      6, ...

Mapa destino por carro, moto y bicicleta

destino1=destinototal
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(destino1) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna5 <- table(destino1$comuna_destino)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$destino1 <- conteo_por_comuna5[match(comunas$comuna, names(conteo_por_comuna5))]
comunas$destino1 <- as.numeric(comunas$destino1)

library(RColorBrewer)
num_colors <- 9
color_paleta_rosados <- brewer.pal(num_colors, "PuRd")

# Generamos el mapa utilizando spplot
spplot(comunas,"destino1",  col.regions = color_paleta_rosados, cuts = 6, main = "Comunas destino para viajes en carro, moto y bicicleta")

## Mapa Destino - Carro

carros2=which(destinototal@data$'TIPO DE VEHÍCULO'==3)

destino2=destinototal[carros2,]

destinocarro=destino2
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(destinocarro) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna6 <- table(destinocarro$comuna_origen)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$destinocarro <- conteo_por_comuna6[match(comunas$comuna, names(conteo_por_comuna6))]
comunas$destinocarro <- as.numeric(comunas$destinocarro)

spplot(comunas,"destinocarro",  col.regions = color_paleta_rosados, cuts = 6, main = "Comunas destino para viajes en carro")

## Mapa Destino - Bicicleta

bicicleta2=which(destinototal@data$'TIPO DE VEHÍCULO'==1)

destino4=destinototal[bicicleta2,]

destinobicicleta=destino4
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(destinobicicleta) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna8 <- table(destinobicicleta$comuna_origen)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$destinobicicleta <- conteo_por_comuna8[match(comunas$comuna, names(conteo_por_comuna8))]
comunas$destinobicicleta <- as.numeric(comunas$destinobicicleta)

spplot(comunas,"destinobicicleta",  col.regions = color_paleta_rosados, cuts = 6, main = "Comunas destino para viajes en bicicleta")

Mapa Destino - Moto

moto2=which(destinototal@data$'TIPO DE VEHÍCULO'==2)

destino3=destinototal[moto2,]

destinomoto=destino3
# Establecer el CRS de origen1 como el mismo que tiene mapacomunas
crs(destinomoto) <- crs(comunas)

# Realizar el conteo de registros por comuna
conteo_por_comuna7 <- table(destinomoto$comuna_origen)

# nueva variable  en mapacomunas y asignar los resultados del conteo
comunas$destinomoto <- conteo_por_comuna7[match(comunas$comuna, names(conteo_por_comuna7))]
comunas$destinomoto <- as.numeric(comunas$destinomoto)

spplot(comunas,"destinomoto",  col.regions = color_paleta_rosados, cuts = 6, main = "Comunas destino para viajes en moto")

Interpretación de los resultados

Análisis para mapas de origen

De acuerdo con los gráficos obtenidos, se puede observar que la mayor concentración de movimientos de origen se encuentra en las comunas 2 y 19 de Cali para los tres medios de transporte analizados. Esto podría indicar que la mayor concentración de personas de la ciudad reside en el noroeste y oeste de la ciudad.

Además, se evidencia que el medio de transporte más utilizado es la moto, con un valor estimado de 1000 trayectos. Le sigue el carro, con un valor estimado de 900 trayectos, y finalmente, la bicicleta, con un valor estimado de 120 trayectos. Esta distribución muestra una clara preferencia por el uso de la moto como principal medio de transporte en estas áreas.

Análisis para mapas destino

De acuerdo con los gráficos obtenidos, se evidencia que los principales destinos a los que se dirigen las personas en la ciudad en estos medios de transporte son, principalmente, la comuna 2, con un valor aproximado de 4000 trayectos. Le sigue la comuna 3, con un valor aproximado de 3500 trayectos, y la comuna 19, con un valor aproximado de 3000 trayectos.

Al realizar el análisis por cada medio de transporte, se observa que las personas que se movilizan en carro tienen como principales destinos las comunas 2, 19, 3 y 17, lo que indica que la mayoría de los trayectos son cortos. Sin embargo, los trayectos de destino en moto y bicicleta presentan una mayor dispersión en diversas zonas de la ciudad. Por último, se evidencia que la zona con menos trayectos de viaje y destino se encuentra en la comuna 12 de la ciudad.

Conclusiones sobre los resultados

Concentración de Movimientos de Origen:

  • Los datos indican que la mayor concentración de movimientos de origen en Cali se encuentra en las comunas 2 y 19. Esta concentración sugiere que un número significativo de residentes vive en las áreas del noroeste y oeste de la ciudad.

Preferencia por Medios de Transporte:

  • El medio de transporte más utilizado es la moto, con aproximadamente 1000 trayectos registrados. Esto refleja una alta preferencia por este medio de transporte, posiblemente debido a su economía y facilidad de desplazamiento en la ciudad.

  • El carro es el segundo medio de transporte más utilizado, con cerca de 900 trayectos. Este dato indica que, aunque menos que las motos, los automóviles también son un medio de transporte popular en Cali.

  • La bicicleta, con alrededor de 120 trayectos, es el medio de transporte menos utilizado de los tres analizados. Esto podría sugerir limitaciones en la infraestructura ciclista o menos inclinación de la población a usar bicicletas para trayectos diarios.

Destinos Principales:

  • Los principales destinos de los trayectos se concentran en la comuna 2, con aproximadamente 4000 trayectos, seguida de la comuna 3 con 3500 trayectos, y la comuna 19 con 3000 trayectos. Esta concentración indica que estas comunas son centros importantes de actividad y destino dentro de la ciudad.

Análisis por Medio de Transporte:

  • Los trayectos en carro se concentran en las comunas 2, 19, 3 y 17, lo que sugiere que los viajes en automóvil tienden a ser más cortos y concentrados en áreas específicas de la ciudad.

  • En contraste, los trayectos en moto y bicicleta presentan una mayor dispersión por toda la ciudad, indicando que estos medios de transporte son utilizados para viajes a una variedad más amplia de destinos.

Zonas con Menor Actividad:

  • La comuna 12 se destaca como la zona con menor número de trayectos de origen y destino. Esto podría indicar menor actividad o conectividad en esta área, lo que podría ser objeto de futuras investigaciones o políticas de desarrollo urbano.