En este ejercicio se realizará una gráfica de cuerdas que muestre la cantidad de personas nacidas en una entidad distinta a la que vivían en el momento del Censo de Población y Vivienda 2020 en México.
Los datos provienen del Instituto Nacional de Geografía e Informática (INEGI) en donde se pueden realizar la búsqueda de personas por entidad federativa según el lugar de nacimiento. Se trabajará con los porcentajes de las personas nacidas en una entidad distinta a la que vivían al momento del censo.
Primero se llaman a las librerías necesarias. Tidyverse es una colección de paquetes orientados a la manipulación, importación, exploración y visualización de datos. Por su parte Circlize es una librería útil para realizar gráficas circulares como las de cuerdas. Finalmente, la librería viridis nos permite colorear los gráficos.
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.0 v dplyr 1.0.5
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## ========================================
## circlize version 0.4.12
## CRAN page: https://cran.r-project.org/package=circlize
## Github page: https://github.com/jokergoo/circlize
## Documentation: https://jokergoo.github.io/circlize_book/book/
##
## If you use it in published research, please cite:
## Gu, Z. circlize implements and enhances circular visualization
## in R. Bioinformatics 2014.
##
## This message can be suppressed by:
## suppressPackageStartupMessages(library(circlize))
## ========================================
## Loading required package: viridisLite
Después se lee el archivo con la información. Es un archivo de texto separado por comas (csv) llamado “Inmigrantes”
datos <- read.csv("Inmigrantes.csv", stringsAsFactors = TRUE, encoding = "UTF-8")
Procedemos a visualizar los datos mediante la función head
head(datos)
## X.U.FEFF.id Entidad Aguascalientes Baja.California
## 1 1 Aguascalientes 0.00 0.76
## 2 2 Baja California 0.44 0.00
## 3 3 Baja California Sur 0.17 4.49
## 4 4 Campeche 0.06 0.30
## 5 5 Coahuila 0.68 0.51
## 6 6 Colima 0.35 1.70
## Baja.California.Sur Campeche Coahuila Colima Chiapas Chihuahua
## 1 0.09 0.08 1.68 0.30 0.63 1.64
## 2 1.07 0.11 0.66 1.04 6.30 1.38
## 3 0.00 0.14 0.89 0.49 3.77 1.22
## 4 0.04 0.00 0.34 0.15 13.10 0.95
## 5 0.11 0.20 0.00 0.18 2.51 6.60
## 6 0.18 0.14 0.46 0.00 2.59 0.51
## Ciudad.de.México Durango Guanajuato Guerrero Hidalgo Jalisco México Michoacán
## 1 20.55 1.76 4.41 1.13 1.21 17.67 6.52 2.54
## 2 5.69 2.99 3.58 6.00 0.75 9.09 2.65 7.79
## 3 7.90 2.68 2.40 21.75 0.73 5.15 4.68 3.58
## 4 4.18 0.75 0.88 1.15 0.43 0.70 1.65 1.88
## 5 5.49 19.37 2.17 1.34 0.90 2.12 2.99 1.44
## 6 7.06 0.53 2.15 8.15 0.65 40.31 3.01 18.43
## Morelos Nayarit Nuevo.León Oaxaca Puebla Querétaro Quintana.Roo
## 1 0.75 0.65 1.17 1.04 1.49 0.63 0.09
## 2 1.04 4.94 0.37 5.16 2.68 0.28 0.09
## 3 0.86 1.91 0.42 5.78 3.65 0.29 0.32
## 4 0.29 0.17 0.37 2.80 1.85 0.16 5.34
## 5 0.50 0.29 14.34 1.85 1.29 0.48 0.16
## 6 0.44 1.40 0.39 1.93 0.97 0.34 0.11
## San.Luis.Potosí Sinaloa Sonora Tabasco Tamaulipas Tlaxcala Veracruz Yucatán
## 1 4.00 0.92 0.55 0.26 1.27 0.27 2.49 0.13
## 2 0.49 17.66 9.01 0.58 0.42 0.35 5.46 0.13
## 3 0.43 14.90 3.66 0.44 0.44 0.41 5.46 0.18
## 4 0.43 0.48 0.22 29.51 1.95 0.19 17.89 11.26
## 5 5.10 1.06 0.76 1.37 5.19 0.25 8.99 0.17
## 6 0.59 1.56 0.66 0.76 0.70 0.18 2.76 0.15
## Zacatecas
## 1 23.34
## 2 1.80
## 3 0.79
## 4 0.52
## 5 11.58
## 6 0.86
Se aprecia que se trata de una tabla donde se identifica el porcentaje de personas nacidas en una entidad distinta en cada una de las 32 entidades de México.
Cada una de las columnas de este dataframe se transformará en una lista.
entidad <- datos$Entidad
Ags <- datos$Aguascalientes
BC <- datos$Baja.California
BCS <- datos$Baja.California.Sur
Camp <- datos$Campeche
Coah <- datos$Coahuila
Col <- datos$Colima
Chis <- datos$Chiapas
Chih <- datos$Chihuahua
CDMX <- datos$Ciudad.de.México
Dgo <- datos$Durango
Gto <- datos$Guanajuato
Gro <- datos$Guerrero
Hgo <- datos$Hidalgo
Jal <- datos$Jalisco
Mex <- datos$México
Mich <- datos$Michoacán
Mor <- datos$Morelos
Nay <- datos$Nayarit
NL <- datos$Nuevo.León
Oax <- datos$Oaxaca
Pue <- datos$Puebla
Qro <- datos$Querétaro
QRoo <- datos$Quintana.Roo
SLP <- datos$San.Luis.Potosí
Sin <- datos$Sinaloa
Son <- datos$Sonora
Tab <- datos$Tabasco
Tams <- datos$Tamaulipas
Tlax <- datos$Tlaxcala
Ver <- datos$Veracruz
Yuc <- datos$Yucatán
Zac <- datos$Zacatecas
Y ahora se conformará una matriz uniendo las listas anteriores con la función rbind() e indicando el nombre de las columnas y las filas con cada una de las entidades federativas del país (por eso se tiene una matriz de 32 por 32)
matriz = matrix(rbind(Ags, BC, BCS, Camp, Coah, Col, Chis, Chih, CDMX, Dgo, Gto, Gro, Hgo, Jal, Mex, Mich, Mor, Nay, NL, Oax, Pue, Qro, QRoo, SLP, Sin, Son, Tab, Tams, Tlax, Ver, Yuc, Zac), nrow = 32, ncol = 32)
rownames(matriz) <- (entidad)
colnames(matriz) <- (entidad)
matriz
## Aguascalientes Baja California Baja California Sur
## Aguascalientes 0.00 0.44 0.17
## Baja California 0.76 0.00 4.49
## Baja California Sur 0.09 1.07 0.00
## Campeche 0.08 0.11 0.14
## Coahuila 1.68 0.66 0.89
## Colima 0.30 1.04 0.49
## Chiapas 0.63 6.30 3.77
## Chihuahua 1.64 1.38 1.22
## Ciudad de México 20.55 5.69 7.90
## Durango 1.76 2.99 2.68
## Guanajuato 4.41 3.58 2.40
## Guerrero 1.13 6.00 21.75
## Hidalgo 1.21 0.75 0.73
## Jalisco 17.67 9.09 5.15
## México 6.52 2.65 4.68
## Michoacán 2.54 7.79 3.58
## Morelos 0.75 1.04 0.86
## Nayarit 0.65 4.94 1.91
## Nuevo León 1.17 0.37 0.42
## Oaxaca 1.04 5.16 5.78
## Puebla 1.49 2.68 3.65
## Querétaro 0.63 0.28 0.29
## Quintana Roo 0.09 0.09 0.32
## San Luis Potosí 4.00 0.49 0.43
## Sinaloa 0.92 17.66 14.90
## Sonora 0.55 9.01 3.66
## Tabasco 0.26 0.58 0.44
## Tamaulipas 1.27 0.42 0.44
## Tlaxcala 0.27 0.35 0.41
## Veracruz 2.49 5.46 5.46
## Yucatán 0.13 0.13 0.18
## Zacatecas 23.34 1.80 0.79
## Campeche Coahuila Colima Chiapas Chihuahua
## Aguascalientes 0.06 0.68 0.35 0.16 0.88
## Baja California 0.30 0.51 1.70 2.93 0.80
## Baja California Sur 0.04 0.11 0.18 0.26 0.12
## Campeche 0.00 0.20 0.14 1.72 0.28
## Coahuila 0.34 0.00 0.46 0.60 13.84
## Colima 0.15 0.18 0.00 0.32 0.15
## Chiapas 13.10 2.51 2.59 0.00 3.05
## Chihuahua 0.95 6.60 0.51 1.06 0.00
## Ciudad de México 4.18 5.49 7.06 12.70 4.75
## Durango 0.75 19.37 0.53 0.45 24.79
## Guanajuato 0.88 2.17 2.15 0.90 1.70
## Guerrero 1.15 1.34 8.15 2.85 1.72
## Hidalgo 0.43 0.90 0.65 0.98 0.67
## Jalisco 0.70 2.12 40.31 2.03 2.10
## México 1.65 2.99 3.01 6.05 2.57
## Michoacán 1.88 1.44 18.43 1.86 1.28
## Morelos 0.29 0.50 0.44 0.78 0.37
## Nayarit 0.17 0.29 1.40 0.47 0.41
## Nuevo León 0.37 14.34 0.39 0.92 1.30
## Oaxaca 2.80 1.85 1.93 12.87 4.59
## Puebla 1.85 1.29 0.97 4.48 1.56
## Querétaro 0.16 0.48 0.34 0.40 0.28
## Quintana Roo 5.34 0.16 0.11 2.46 0.15
## San Luis Potosí 0.43 5.10 0.59 0.48 0.83
## Sinaloa 0.48 1.06 1.56 1.00 3.92
## Sonora 0.22 0.76 0.66 0.71 2.77
## Tabasco 29.51 1.37 0.76 23.37 1.02
## Tamaulipas 1.95 5.19 0.70 1.49 0.96
## Tlaxcala 0.19 0.25 0.18 0.52 0.19
## Veracruz 17.89 8.99 2.76 13.83 15.24
## Yucatán 11.26 0.17 0.15 1.08 0.19
## Zacatecas 0.52 11.58 0.86 0.28 7.52
## Ciudad de México Durango Guanajuato Guerrero Hidalgo
## Aguascalientes 0.42 0.67 1.28 0.16 0.17
## Baja California 0.49 1.89 1.18 2.06 0.38
## Baja California Sur 0.09 0.32 0.12 0.87 0.04
## Campeche 0.20 0.12 0.13 0.20 0.08
## Coahuila 0.62 36.94 1.23 0.39 0.29
## Colima 0.19 0.14 0.36 0.70 0.10
## Chiapas 2.25 0.52 1.11 1.56 0.86
## Chihuahua 0.66 15.12 1.08 0.70 0.35
## Ciudad de México 0.00 3.95 21.61 18.29 35.10
## Durango 0.49 0.00 0.84 0.38 0.25
## Guanajuato 4.60 1.27 0.00 1.33 1.48
## Guerrero 6.01 0.82 2.58 0.00 1.62
## Hidalgo 6.93 0.51 1.90 1.34 0.00
## Jalisco 2.66 2.43 10.48 2.42 1.17
## México 23.09 2.15 10.98 15.89 25.60
## Michoacán 7.20 1.10 12.42 13.85 1.72
## Morelos 2.08 0.27 0.97 11.18 0.69
## Nayarit 0.24 1.23 0.64 0.51 0.13
## Nuevo León 0.73 1.97 1.11 0.40 0.71
## Oaxaca 9.91 0.75 1.77 11.75 1.83
## Puebla 11.86 0.87 2.22 5.53 7.21
## Querétaro 1.45 0.31 9.88 0.49 2.87
## Quintana Roo 0.21 0.14 0.12 0.45 0.10
## San Luis Potosí 1.43 0.97 4.30 0.62 4.02
## Sinaloa 0.82 10.34 1.14 1.74 0.32
## Sonora 0.53 1.06 0.75 0.76 0.21
## Tabasco 0.67 0.22 0.49 0.58 0.38
## Tamaulipas 0.94 1.45 2.48 0.73 1.11
## Tlaxcala 2.26 0.12 0.53 0.38 2.61
## Veracruz 9.63 1.83 4.29 4.19 8.20
## Yucatán 0.43 0.09 0.17 0.23 0.11
## Zacatecas 0.88 10.44 1.85 0.32 0.32
## Jalisco México Michoacán Morelos Nayarit Nuevo León
## Aguascalientes 3.92 0.15 0.31 0.14 0.46 0.43
## Baja California 2.39 0.19 1.83 0.40 4.02 0.35
## Baja California Sur 0.30 0.03 0.17 0.05 0.39 0.07
## Campeche 0.13 0.07 0.16 0.09 0.09 0.16
## Coahuila 1.07 0.20 0.54 0.29 0.47 10.62
## Colima 4.78 0.06 3.59 0.09 1.12 0.13
## Chiapas 2.27 1.04 1.64 1.02 3.91 2.27
## Chihuahua 1.15 0.21 0.53 0.31 0.71 1.39
## Ciudad de México 12.30 59.91 18.07 24.70 4.82 4.95
## Durango 1.28 0.20 0.50 0.22 1.89 2.82
## Guanajuato 5.71 2.48 13.34 1.28 2.17 1.63
## Guerrero 4.51 2.90 16.07 33.46 5.78 1.04
## Hidalgo 1.92 5.01 1.18 1.53 0.54 3.02
## Jalisco 0.00 1.06 14.08 1.01 45.86 1.67
## México 4.78 0.00 13.20 12.40 2.69 2.43
## Michoacán 15.22 3.90 0.00 3.05 5.74 1.07
## Morelos 0.70 0.96 0.93 0.00 0.56 0.36
## Nayarit 7.19 0.10 0.90 0.16 0.00 0.17
## Nuevo León 0.97 0.23 0.45 0.29 0.34 0.00
## Oaxaca 2.21 5.37 1.65 3.90 1.45 2.01
## Puebla 1.93 6.24 1.60 8.41 1.07 1.34
## Querétaro 0.71 0.90 1.47 0.37 0.49 0.54
## Quintana Roo 0.17 0.07 0.13 0.13 0.16 0.13
## San Luis Potosí 2.17 0.81 0.75 0.48 0.56 21.96
## Sinaloa 4.50 0.23 1.07 0.37 6.93 0.84
## Sonora 1.75 0.13 0.68 0.22 1.95 0.64
## Tabasco 0.58 0.26 0.48 0.34 0.35 1.57
## Tamaulipas 1.20 0.33 0.88 0.43 0.53 15.65
## Tlaxcala 0.33 1.07 0.31 0.54 0.15 0.18
## Veracruz 4.80 5.34 2.82 3.88 1.99 14.95
## Yucatán 0.21 0.12 0.12 0.14 0.10 0.16
## Zacatecas 8.86 0.47 0.55 0.27 2.75 5.47
## Oaxaca Puebla Querétaro Quintana Roo San Luis Potosí
## Aguascalientes 0.11 0.18 0.41 0.11 1.66
## Baja California 2.01 0.63 0.40 0.21 0.43
## Baja California Sur 0.37 0.12 0.07 0.05 0.08
## Campeche 0.41 0.23 0.12 5.01 0.13
## Coahuila 0.35 0.42 0.83 0.34 2.47
## Colima 0.21 0.12 0.18 0.10 0.20
## Chiapas 9.54 2.53 1.33 12.34 0.75
## Chihuahua 0.94 0.47 0.76 0.33 1.04
## Ciudad de México 15.98 18.47 33.07 10.62 13.33
## Durango 0.28 0.25 0.66 0.34 0.99
## Guanajuato 0.81 1.08 11.81 0.53 7.11
## Guerrero 7.24 4.02 3.17 3.30 1.55
## Hidalgo 1.10 4.58 5.20 0.54 3.92
## Jalisco 1.34 1.24 2.46 1.21 4.51
## México 11.53 10.69 13.42 3.16 6.21
## Michoacán 1.56 1.51 5.51 0.81 2.02
## Morelos 1.15 3.28 1.29 0.71 0.59
## Nayarit 0.24 0.16 0.29 0.14 0.34
## Nuevo León 0.61 0.50 0.87 0.47 9.76
## Oaxaca 0.00 11.18 1.95 2.04 1.33
## Puebla 8.38 0.00 2.64 1.90 1.89
## Querétaro 0.36 0.44 0.00 0.18 3.19
## Quintana Roo 0.40 0.27 0.14 0.00 0.11
## San Luis Potosí 0.52 0.57 2.55 0.26 0.00
## Sinaloa 0.98 0.49 0.77 0.32 0.75
## Sonora 0.64 0.32 0.46 0.16 0.62
## Tabasco 1.37 1.29 0.63 15.20 0.52
## Tamaulipas 0.95 0.85 1.78 0.48 14.85
## Tlaxcala 0.51 8.65 0.60 0.31 0.34
## Veracruz 29.57 24.96 5.89 13.53 7.22
## Yucatán 0.35 0.27 0.18 25.17 0.15
## Zacatecas 0.20 0.24 0.55 0.12 11.96
## Sinaloa Sonora Tabasco Tamaulipas Tlaxcala Veracruz
## Aguascalientes 0.31 0.32 0.08 0.33 0.14 0.16
## Baja California 9.17 8.75 0.38 0.21 0.39 0.82
## Baja California Sur 1.31 0.71 0.04 0.04 0.06 0.13
## Campeche 0.15 0.10 6.66 0.34 0.11 0.97
## Coahuila 1.21 1.11 0.47 3.95 0.21 0.63
## Colima 0.65 0.42 0.14 0.16 0.07 0.21
## Chiapas 1.53 3.18 31.67 1.90 1.15 4.94
## Chihuahua 6.91 8.64 0.55 0.61 0.25 1.32
## Ciudad de México 4.20 3.86 6.53 3.97 17.61 11.67
## Durango 13.35 3.13 0.20 1.43 0.16 0.32
## Guanajuato 2.65 2.58 0.59 3.15 0.88 0.96
## Guerrero 9.26 2.96 1.10 1.09 1.41 1.69
## Hidalgo 0.64 0.51 0.78 1.73 6.79 5.11
## Jalisco 6.37 5.46 0.97 1.47 0.85 1.32
## México 2.20 1.96 2.45 2.10 10.85 7.07
## Michoacán 3.45 4.04 1.22 1.52 1.16 1.42
## Morelos 0.51 0.49 0.48 0.32 0.82 0.76
## Nayarit 8.58 4.12 0.17 0.15 0.11 0.19
## Nuevo León 0.70 0.62 0.72 8.87 0.20 1.34
## Oaxaca 4.34 3.95 4.04 1.46 2.41 16.39
## Puebla 1.28 1.42 3.47 1.81 44.17 15.61
## Querétaro 0.27 0.25 0.18 0.93 0.35 0.42
## Quintana Roo 0.11 0.09 3.00 0.13 0.12 0.84
## San Luis Potosí 0.82 0.68 0.66 17.28 0.43 2.43
## Sinaloa 0.00 34.01 0.49 0.42 0.25 0.62
## Sonora 12.28 0.00 0.27 0.27 0.21 0.40
## Tabasco 0.43 0.47 0.00 1.55 0.54 5.86
## Tamaulipas 0.69 0.59 2.59 0.00 0.39 14.67
## Tlaxcala 0.20 0.18 0.29 0.14 0.00 0.83
## Veracruz 4.50 3.68 27.41 41.21 7.59 0.00
## Yucatán 0.15 0.14 2.22 0.15 0.12 0.64
## Zacatecas 1.80 1.56 0.17 1.26 0.20 0.26
## Yucatán Zacatecas
## Aguascalientes 0.15 20.35
## Baja California 0.38 1.13
## Baja California Sur 0.07 0.09
## Campeche 15.93 0.13
## Coahuila 0.51 5.87
## Colima 0.14 0.30
## Chiapas 6.58 0.48
## Chihuahua 0.56 3.84
## Ciudad de México 18.75 7.15
## Durango 0.26 11.50
## Guanajuato 0.81 2.27
## Guerrero 1.21 0.88
## Hidalgo 0.64 0.86
## Jalisco 1.59 19.62
## México 4.37 4.12
## Michoacán 1.09 1.44
## Morelos 0.72 0.28
## Nayarit 0.15 1.18
## Nuevo León 1.10 2.85
## Oaxaca 2.40 0.68
## Puebla 1.92 1.01
## Querétaro 0.34 0.43
## Quintana Roo 13.40 0.06
## San Luis Potosí 0.43 8.18
## Sinaloa 0.55 1.12
## Sonora 0.40 0.63
## Tabasco 13.59 0.32
## Tamaulipas 1.25 1.26
## Tlaxcala 0.22 0.18
## Veracruz 10.32 1.68
## Yucatán 0.00 0.11
## Zacatecas 0.17 0.00
Con esta matriz ya es posible realizar un diagrama de cuerdas
chordDiagram(matriz)
## Note: The second link end is drawn out of sector ' Baja California'.
## Note: The second link end is drawn out of sector ' Coahuila'.
## Note: The second link end is drawn out of sector ' Ciudad de México'.
## Note: The second link end is drawn out of sector ' Durango'.
## Note: The second link end is drawn out of sector ' Hidalgo'.
## Note: The second link end is drawn out of sector ' Jalisco'.
## Note: The second link end is drawn out of sector ' Oaxaca'.
## Note: The second link end is drawn out of sector ' Puebla'.
## Note: The second link end is drawn out of sector ' Tabasco'.
## Note: The second link end is drawn out of sector ' Tamaulipas'.
## Note: The second link end is drawn out of sector ' Veracruz'.
No obstante, el resultado no es el más apropiado, por lo que debe mejorarse, primero, indicando un color distinto para cada una de las entidades con la función grid.col, y después, indicando algunas propiedades del gráfico como transparencia.
grid.col = c("Aguascalientes" = "#f5ac1b", "Baja California" ="#c20e80", "Baja California Sur" = "#15b7bf", "Campeche" = "#cc4f2d", "Coahuila" ="#ccaf2d", "Colima"="#31b55d", "Chiapas" ="#8e39bd", "Chihuahua" ="#cc0c0c", "Ciudad de México" = "#82043b", "Durango" ="#759636", "Guanajuato" ="#8553db", "Guerrero" ="#913f10", "Hidalgo" = "#43b7cc", "Jalisco" ="#e0841b", "México" ="#e038de", "Michoacán" = "#d9485b", "Morelos" = "#780cb3", "Nayarit" ="#a10838", "Nuevo León" = "#32a15a", "Oaxaca" = "#a9d428", "Puebla" ="#f0f01f", "Querétaro"="#c2448f", "Quintana Roo" ="#3090b0", "San Luis Potosí" ="#2f9c32", "Sinaloa" = "#32bf9c", "Sonora" ="#e34660", "Tabasco" ="#1f3f8f", "Tamaulipas" ="#a6341f", "Tlaxcala" = "#c7cf3e", "Veracruz" ="#6887e3", "Yucatán" ="#ad4ce6", "Zacatecas" = "#187ca1")
chordDiagram(
x = matriz, #datos
grid.col = grid.col, #colores
transparency = 0.1, #transparencia
directional = 1, #dirección
direction.type = c("arrows", "diffHeight"), #Tipo de dirección y ancho
diffHeight = 0, # Espacio en llegada de flujos
annotationTrack = c("name", "grid"), #nombre de sectores
annotationTrackHeight = c(0.07, 0.07), #altura del espacio para nombres
link.arr.type = "big.arrow",
link.largest.ontop = TRUE)
## Note: The second link end is drawn out of sector ' Tamaulipas'.
## Note: The second link end is drawn out of sector ' Coahuila'.
## Note: The second link end is drawn out of sector ' Puebla'.
## Note: The second link end is drawn out of sector ' Ciudad de México'.
## Note: The second link end is drawn out of sector ' Veracruz'.
## Note: The second link end is drawn out of sector ' Baja California'.
## Note: The second link end is drawn out of sector ' Hidalgo'.
## Note: The second link end is drawn out of sector ' Durango'.
## Note: The second link end is drawn out of sector ' Tabasco'.
## Note: The second link end is drawn out of sector ' Jalisco'.
## Note: The second link end is drawn out of sector ' Oaxaca'.
Aún los nombres de los sectores no son claros, por lo que tal vez convenga primero abreviarlos
entidades <- c("Ags", "BC", "BCS", "Camp", "Coah", "Col", "Chis", "Chih" , "CDMX", "Dgo", "Gto", "Gro", "Hgo", "Jal", "Méx", "Mich", "Mor", "Nay", "NL" , "Oax", "Pue", "Qro", "Q Roo", "SLP", "Sin", "Son", "Tab", "Tams", "Tlax", "Ver", "Yuc", "Zacs")
Se vuelve a hacer la matriz
matriz2 = matrix(rbind(Ags, BC, BCS, Camp, Coah, Col, Chis, Chih, CDMX, Dgo, Gto, Gro, Hgo, Jal, Mex, Mich, Mor, Nay, NL, Oax, Pue, Qro, QRoo, SLP, Sin, Son, Tab, Tams, Tlax, Ver, Yuc, Zac), nrow = 32, ncol = 32)
rownames(matriz2) <- (entidades)
colnames(matriz2) <- (entidades)
matriz2
## Ags BC BCS Camp Coah Col Chis Chih CDMX Dgo Gto Gro
## Ags 0.00 0.44 0.17 0.06 0.68 0.35 0.16 0.88 0.42 0.67 1.28 0.16
## BC 0.76 0.00 4.49 0.30 0.51 1.70 2.93 0.80 0.49 1.89 1.18 2.06
## BCS 0.09 1.07 0.00 0.04 0.11 0.18 0.26 0.12 0.09 0.32 0.12 0.87
## Camp 0.08 0.11 0.14 0.00 0.20 0.14 1.72 0.28 0.20 0.12 0.13 0.20
## Coah 1.68 0.66 0.89 0.34 0.00 0.46 0.60 13.84 0.62 36.94 1.23 0.39
## Col 0.30 1.04 0.49 0.15 0.18 0.00 0.32 0.15 0.19 0.14 0.36 0.70
## Chis 0.63 6.30 3.77 13.10 2.51 2.59 0.00 3.05 2.25 0.52 1.11 1.56
## Chih 1.64 1.38 1.22 0.95 6.60 0.51 1.06 0.00 0.66 15.12 1.08 0.70
## CDMX 20.55 5.69 7.90 4.18 5.49 7.06 12.70 4.75 0.00 3.95 21.61 18.29
## Dgo 1.76 2.99 2.68 0.75 19.37 0.53 0.45 24.79 0.49 0.00 0.84 0.38
## Gto 4.41 3.58 2.40 0.88 2.17 2.15 0.90 1.70 4.60 1.27 0.00 1.33
## Gro 1.13 6.00 21.75 1.15 1.34 8.15 2.85 1.72 6.01 0.82 2.58 0.00
## Hgo 1.21 0.75 0.73 0.43 0.90 0.65 0.98 0.67 6.93 0.51 1.90 1.34
## Jal 17.67 9.09 5.15 0.70 2.12 40.31 2.03 2.10 2.66 2.43 10.48 2.42
## Méx 6.52 2.65 4.68 1.65 2.99 3.01 6.05 2.57 23.09 2.15 10.98 15.89
## Mich 2.54 7.79 3.58 1.88 1.44 18.43 1.86 1.28 7.20 1.10 12.42 13.85
## Mor 0.75 1.04 0.86 0.29 0.50 0.44 0.78 0.37 2.08 0.27 0.97 11.18
## Nay 0.65 4.94 1.91 0.17 0.29 1.40 0.47 0.41 0.24 1.23 0.64 0.51
## NL 1.17 0.37 0.42 0.37 14.34 0.39 0.92 1.30 0.73 1.97 1.11 0.40
## Oax 1.04 5.16 5.78 2.80 1.85 1.93 12.87 4.59 9.91 0.75 1.77 11.75
## Pue 1.49 2.68 3.65 1.85 1.29 0.97 4.48 1.56 11.86 0.87 2.22 5.53
## Qro 0.63 0.28 0.29 0.16 0.48 0.34 0.40 0.28 1.45 0.31 9.88 0.49
## Q Roo 0.09 0.09 0.32 5.34 0.16 0.11 2.46 0.15 0.21 0.14 0.12 0.45
## SLP 4.00 0.49 0.43 0.43 5.10 0.59 0.48 0.83 1.43 0.97 4.30 0.62
## Sin 0.92 17.66 14.90 0.48 1.06 1.56 1.00 3.92 0.82 10.34 1.14 1.74
## Son 0.55 9.01 3.66 0.22 0.76 0.66 0.71 2.77 0.53 1.06 0.75 0.76
## Tab 0.26 0.58 0.44 29.51 1.37 0.76 23.37 1.02 0.67 0.22 0.49 0.58
## Tams 1.27 0.42 0.44 1.95 5.19 0.70 1.49 0.96 0.94 1.45 2.48 0.73
## Tlax 0.27 0.35 0.41 0.19 0.25 0.18 0.52 0.19 2.26 0.12 0.53 0.38
## Ver 2.49 5.46 5.46 17.89 8.99 2.76 13.83 15.24 9.63 1.83 4.29 4.19
## Yuc 0.13 0.13 0.18 11.26 0.17 0.15 1.08 0.19 0.43 0.09 0.17 0.23
## Zacs 23.34 1.80 0.79 0.52 11.58 0.86 0.28 7.52 0.88 10.44 1.85 0.32
## Hgo Jal Méx Mich Mor Nay NL Oax Pue Qro Q Roo SLP
## Ags 0.17 3.92 0.15 0.31 0.14 0.46 0.43 0.11 0.18 0.41 0.11 1.66
## BC 0.38 2.39 0.19 1.83 0.40 4.02 0.35 2.01 0.63 0.40 0.21 0.43
## BCS 0.04 0.30 0.03 0.17 0.05 0.39 0.07 0.37 0.12 0.07 0.05 0.08
## Camp 0.08 0.13 0.07 0.16 0.09 0.09 0.16 0.41 0.23 0.12 5.01 0.13
## Coah 0.29 1.07 0.20 0.54 0.29 0.47 10.62 0.35 0.42 0.83 0.34 2.47
## Col 0.10 4.78 0.06 3.59 0.09 1.12 0.13 0.21 0.12 0.18 0.10 0.20
## Chis 0.86 2.27 1.04 1.64 1.02 3.91 2.27 9.54 2.53 1.33 12.34 0.75
## Chih 0.35 1.15 0.21 0.53 0.31 0.71 1.39 0.94 0.47 0.76 0.33 1.04
## CDMX 35.10 12.30 59.91 18.07 24.70 4.82 4.95 15.98 18.47 33.07 10.62 13.33
## Dgo 0.25 1.28 0.20 0.50 0.22 1.89 2.82 0.28 0.25 0.66 0.34 0.99
## Gto 1.48 5.71 2.48 13.34 1.28 2.17 1.63 0.81 1.08 11.81 0.53 7.11
## Gro 1.62 4.51 2.90 16.07 33.46 5.78 1.04 7.24 4.02 3.17 3.30 1.55
## Hgo 0.00 1.92 5.01 1.18 1.53 0.54 3.02 1.10 4.58 5.20 0.54 3.92
## Jal 1.17 0.00 1.06 14.08 1.01 45.86 1.67 1.34 1.24 2.46 1.21 4.51
## Méx 25.60 4.78 0.00 13.20 12.40 2.69 2.43 11.53 10.69 13.42 3.16 6.21
## Mich 1.72 15.22 3.90 0.00 3.05 5.74 1.07 1.56 1.51 5.51 0.81 2.02
## Mor 0.69 0.70 0.96 0.93 0.00 0.56 0.36 1.15 3.28 1.29 0.71 0.59
## Nay 0.13 7.19 0.10 0.90 0.16 0.00 0.17 0.24 0.16 0.29 0.14 0.34
## NL 0.71 0.97 0.23 0.45 0.29 0.34 0.00 0.61 0.50 0.87 0.47 9.76
## Oax 1.83 2.21 5.37 1.65 3.90 1.45 2.01 0.00 11.18 1.95 2.04 1.33
## Pue 7.21 1.93 6.24 1.60 8.41 1.07 1.34 8.38 0.00 2.64 1.90 1.89
## Qro 2.87 0.71 0.90 1.47 0.37 0.49 0.54 0.36 0.44 0.00 0.18 3.19
## Q Roo 0.10 0.17 0.07 0.13 0.13 0.16 0.13 0.40 0.27 0.14 0.00 0.11
## SLP 4.02 2.17 0.81 0.75 0.48 0.56 21.96 0.52 0.57 2.55 0.26 0.00
## Sin 0.32 4.50 0.23 1.07 0.37 6.93 0.84 0.98 0.49 0.77 0.32 0.75
## Son 0.21 1.75 0.13 0.68 0.22 1.95 0.64 0.64 0.32 0.46 0.16 0.62
## Tab 0.38 0.58 0.26 0.48 0.34 0.35 1.57 1.37 1.29 0.63 15.20 0.52
## Tams 1.11 1.20 0.33 0.88 0.43 0.53 15.65 0.95 0.85 1.78 0.48 14.85
## Tlax 2.61 0.33 1.07 0.31 0.54 0.15 0.18 0.51 8.65 0.60 0.31 0.34
## Ver 8.20 4.80 5.34 2.82 3.88 1.99 14.95 29.57 24.96 5.89 13.53 7.22
## Yuc 0.11 0.21 0.12 0.12 0.14 0.10 0.16 0.35 0.27 0.18 25.17 0.15
## Zacs 0.32 8.86 0.47 0.55 0.27 2.75 5.47 0.20 0.24 0.55 0.12 11.96
## Sin Son Tab Tams Tlax Ver Yuc Zacs
## Ags 0.31 0.32 0.08 0.33 0.14 0.16 0.15 20.35
## BC 9.17 8.75 0.38 0.21 0.39 0.82 0.38 1.13
## BCS 1.31 0.71 0.04 0.04 0.06 0.13 0.07 0.09
## Camp 0.15 0.10 6.66 0.34 0.11 0.97 15.93 0.13
## Coah 1.21 1.11 0.47 3.95 0.21 0.63 0.51 5.87
## Col 0.65 0.42 0.14 0.16 0.07 0.21 0.14 0.30
## Chis 1.53 3.18 31.67 1.90 1.15 4.94 6.58 0.48
## Chih 6.91 8.64 0.55 0.61 0.25 1.32 0.56 3.84
## CDMX 4.20 3.86 6.53 3.97 17.61 11.67 18.75 7.15
## Dgo 13.35 3.13 0.20 1.43 0.16 0.32 0.26 11.50
## Gto 2.65 2.58 0.59 3.15 0.88 0.96 0.81 2.27
## Gro 9.26 2.96 1.10 1.09 1.41 1.69 1.21 0.88
## Hgo 0.64 0.51 0.78 1.73 6.79 5.11 0.64 0.86
## Jal 6.37 5.46 0.97 1.47 0.85 1.32 1.59 19.62
## Méx 2.20 1.96 2.45 2.10 10.85 7.07 4.37 4.12
## Mich 3.45 4.04 1.22 1.52 1.16 1.42 1.09 1.44
## Mor 0.51 0.49 0.48 0.32 0.82 0.76 0.72 0.28
## Nay 8.58 4.12 0.17 0.15 0.11 0.19 0.15 1.18
## NL 0.70 0.62 0.72 8.87 0.20 1.34 1.10 2.85
## Oax 4.34 3.95 4.04 1.46 2.41 16.39 2.40 0.68
## Pue 1.28 1.42 3.47 1.81 44.17 15.61 1.92 1.01
## Qro 0.27 0.25 0.18 0.93 0.35 0.42 0.34 0.43
## Q Roo 0.11 0.09 3.00 0.13 0.12 0.84 13.40 0.06
## SLP 0.82 0.68 0.66 17.28 0.43 2.43 0.43 8.18
## Sin 0.00 34.01 0.49 0.42 0.25 0.62 0.55 1.12
## Son 12.28 0.00 0.27 0.27 0.21 0.40 0.40 0.63
## Tab 0.43 0.47 0.00 1.55 0.54 5.86 13.59 0.32
## Tams 0.69 0.59 2.59 0.00 0.39 14.67 1.25 1.26
## Tlax 0.20 0.18 0.29 0.14 0.00 0.83 0.22 0.18
## Ver 4.50 3.68 27.41 41.21 7.59 0.00 10.32 1.68
## Yuc 0.15 0.14 2.22 0.15 0.12 0.64 0.00 0.11
## Zacs 1.80 1.56 0.17 1.26 0.20 0.26 0.17 0.00
Indicaremos nuevamente un color distinto para cada entidad
grid.col2 = c("Ags" = "#db9807", "BC" ="#0766db", "BCS" = "#05afb5", "Camp" = "#9506c9", "Coah" ="#d42502", "Col"="#a2ba04", "Chis" ="#05a112", "Chih" ="#086ca6", "CDMX" = "#9c056c", "Dgo" ="#1da15a", "Gto" ="#c728aa", "Gro" ="#a64107", "Hgo" = "#009ac9", "Jal" ="#5eb325", "Méx" ="#4b519c", "Mich" = "#d48806", "Mor" = "#02732a", "Nay" ="#db4868", "NL" = "#9e07a3", "Oax" = "#b00ea2", "Pue" ="#d6d331", "Qro"="#ad0c0c", "Q Roo" ="#00c4c1", "SLP" ="#1dad3a", "Sin" = "#ad801d", "Son" ="#e84a7c", "Tab" ="#2fa132", "Tams" ="#db891d", "Tlax" = "#a43bd1", "Ver" ="#1aa162", "Yuc" ="#ad2697", "Zacs" = "#a3b7d9")
Y generamos un nuevo diagrama de cuerdas con la nueva matriz, la nueva rampa de color y especificando que el nombre de las entidades aparezcan dentro de los sectores circulares
chordDiagram(
x = matriz2, #datos
grid.col = grid.col2, #colores
transparency = 0.1, #transparencia
directional = 1,
direction.type = c("arrows", "diffHeight"),
diffHeight = 0,
annotationTrack = "grid",
annotationTrackHeight = c(0.1, 0.1), #altura del espacio para nombres
link.arr.type = "big.arrow",
link.largest.ontop = TRUE)
## Note: The second link end is drawn out of sector 'Tams'.
## Note: The second link end is drawn out of sector 'Coah'.
## Note: The second link end is drawn out of sector 'Pue'.
## Note: The second link end is drawn out of sector 'CDMX'.
## Note: The second link end is drawn out of sector 'Ver'.
## Note: The second link end is drawn out of sector 'BC'.
## Note: The second link end is drawn out of sector 'Hgo'.
## Note: The second link end is drawn out of sector 'Dgo'.
## Note: The second link end is drawn out of sector 'Tab'.
## Note: The second link end is drawn out of sector 'Jal'.
## Note: The second link end is drawn out of sector 'Oax'.
for(si in get.all.sector.index()) {
xlim = get.cell.meta.data("xlim", sector.index = si, track.index = 1)
ylim = get.cell.meta.data("ylim", sector.index = si, track.index = 1)
circos.text(mean(xlim), mean(ylim), si, sector.index = si, track.index = 1,
facing = "bending", cex= 0.5, col = "black") #Disposición, tamaño y color de fuente de los nombres
}
Mejoró bastante, pero ahora vamos a probar que los nombres de las entidades estén por fuera del gráfico y en disposición como los números en un reloj.
chordDiagram(
x = matriz2, #datos
grid.col = grid.col2, #colores
transparency = 0.25, #transparencia
directional = 1,
direction.type = c("arrows", "diffHeight"),
diffHeight = 0,
annotationTrack = c("names", "grid"),
annotationTrackHeight = c(0.07, 0.07),
preAllocateTracks = list(track.height = 0.1),
link.arr.type = "big.arrow",
link.largest.ontop = TRUE)
## Note: The second link end is drawn out of sector 'Tams'.
## Note: The second link end is drawn out of sector 'Coah'.
## Note: The second link end is drawn out of sector 'Pue'.
## Note: The second link end is drawn out of sector 'CDMX'.
## Note: The second link end is drawn out of sector 'Ver'.
## Note: The second link end is drawn out of sector 'BC'.
## Note: The second link end is drawn out of sector 'Hgo'.
## Note: The second link end is drawn out of sector 'Dgo'.
## Note: The second link end is drawn out of sector 'Tab'.
## Note: The second link end is drawn out of sector 'Jal'.
## Note: The second link end is drawn out of sector 'Oax'.
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
xplot = get.cell.meta.data("xplot")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
if(abs(xplot[2] - xplot[1]) < 30) {
circos.text(mean(xlim), ylim[1], sector.name, facing = "clockwise",
niceFacing = TRUE, adj = c(0, 0.5), cex= 0.7, col = "gray20")
} else {
circos.text(mean(xlim), ylim[1], sector.name, facing = "clockwise",
niceFacing = TRUE, adj = c(0.5, 0), cex= 0.7, col = "gray20")
}
}, bg.border = NA)
Finalmente, probaremos con una rampa de color de la librería viridis.
circos.clear()
circos.par(start.degree = 90, gap.degree = 4, track.margin = c(-0.1, 0.1), points.overflow.warning = FALSE)
par(mar = rep(0, 4))
# Paleta de colores
mycolor <- viridis(32, alpha = 1, begin = 0, end = 1, option = "D")
mycolor <- mycolor[sample(1:32)]
# Base plot
chordDiagram(
x = matriz2,
grid.col = mycolor,
transparency = 0.25,
directional = 1,
direction.type = c("arrows", "diffHeight"),
diffHeight = -0.03,
annotationTrack = c("names", "grid"),
annotationTrackHeight = c(0.1, 0.1),
link.arr.type = "big.arrow",
link.sort = TRUE,
link.largest.ontop = TRUE)
## Note: The second link end is drawn out of sector 'Hgo'.
## Note: The second link end is drawn out of sector 'Tab'.
## Note: The second link end is drawn out of sector 'Tams'.
## Note: The second link end is drawn out of sector 'BC'.
## Note: The second link end is drawn out of sector 'CDMX'.
## Note: The second link end is drawn out of sector 'Dgo'.
## Note: The second link end is drawn out of sector 'Coah'.
## Note: The second link end is drawn out of sector 'Oax'.
## Note: The second link end is drawn out of sector 'Pue'.
## Note: The second link end is drawn out of sector 'Jal'.
## Note: The second link end is drawn out of sector 'Ver'.
# Añadir texto y ejes
circos.trackPlotRegion(
track.index = 1,
bg.border = NA,
panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
sector.index = get.cell.meta.data("sector.index")
xplot = get.cell.meta.data("xplot")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
if(abs(xplot[2] - xplot[1]) < 30) {
circos.text(mean(xlim), ylim[1], sector.name, facing = "bending",
niceFacing = TRUE, adj = c(0, -1), cex= 0.6, col = "gray20")
} else {
circos.text(mean(xlim), ylim[1], sector.name, facing = "bending",
niceFacing = TRUE, adj = c(0, -1), cex= 0.6, col = "gray20")
}
}
)
Se realizaron varias pruebas con resultados satisfactorios, sin embargo, cuando son muchos datos es complicado ver los detalles, por lo que ahora se harán algunas gráficas de cuerdas de la migración entre las entidades que conforman la Megalópolis de la Región Centro de México: Ciudad de México, Hidalgo, México, Morelos, Puebla, Querétaro y Tlaxcala.
Primero se leen los datos cuya fuente es el Censo de Población y Vivienda del INEGI 2020.
mega <- read.csv("megalopolis.csv", stringsAsFactors = TRUE, encoding = "UTF-8")
head(mega)
## X.U.FEFF.id Entidad Ciudad.de.México Hidalgo México Morelos Puebla
## 1 9 Ciudad de México 0.00 6.93 23.09 2.08 11.86
## 2 13 Hidalgo 35.10 0.00 25.60 0.69 7.21
## 3 15 México 59.91 5.01 0.00 0.96 6.24
## 4 17 Morelos 24.70 1.53 12.40 0.00 8.41
## 5 21 Puebla 18.47 4.58 10.69 3.28 0.00
## 6 22 Querétaro 33.07 5.20 13.42 1.29 2.64
## Querétaro Tlaxcala
## 1 1.45 2.26
## 2 2.87 2.61
## 3 0.90 1.07
## 4 0.37 0.54
## 5 0.44 8.65
## 6 0.00 0.60
Se aprecia que se trata de una tabla donde se identifica el porcentaje de personas nacidas en una entidad distinta en cada una de las 7 entidades de México que conforman la Megalópolis de la Región Centro.
Se procederá como anteriormente, por lo que cada una de las columnas se transformará en una lista.
estados <- c("Ciudad de México", "Hidalgo", "México", "Morelos", "Puebla", "Querétaro", "Tlaxcala")
CiudadMexico <- mega$Ciudad.de.México
Hidalgo <- mega$Hidalgo
Mexico <- mega$México
Morelos <- mega$Morelos
Puebla <- mega$Puebla
Queretaro <- mega$Querétaro
Tlaxcala <- mega$Tlaxcala
Y ahora se genera una matriz uniendo cada una de las listas anteriormente generadas.
matriz_mega = matrix(rbind(CiudadMexico, Hidalgo, Mexico, Morelos, Puebla, Queretaro, Tlaxcala), nrow = 7, ncol = 7)
rownames(matriz_mega) <- (estados)
colnames(matriz_mega) <- (estados)
matriz_mega
## Ciudad de México Hidalgo México Morelos Puebla Querétaro
## Ciudad de México 0.00 35.10 59.91 24.70 18.47 33.07
## Hidalgo 6.93 0.00 5.01 1.53 4.58 5.20
## México 23.09 25.60 0.00 12.40 10.69 13.42
## Morelos 2.08 0.69 0.96 0.00 3.28 1.29
## Puebla 11.86 7.21 6.24 8.41 0.00 2.64
## Querétaro 1.45 2.87 0.90 0.37 0.44 0.00
## Tlaxcala 2.26 2.61 1.07 0.54 8.65 0.60
## Tlaxcala
## Ciudad de México 17.61
## Hidalgo 6.79
## México 10.85
## Morelos 0.82
## Puebla 44.17
## Querétaro 0.35
## Tlaxcala 0.00
Con esta matriz, ya es posible generar un diagrama de cuerdas.
chordDiagram(matriz_mega)
## Note: The second link end is drawn out of sector 'México'.
## Note: The second link end is drawn out of sector 'Morelos'.
## Note: The second link end is drawn out of sector 'Tlaxcala'.
Se generó la gráfica de cuerdas, pero vamos a mejorarla primero agregando un color de nuestra preferencia por estado
grid.col3 = c("Ciudad de México" = "#9c34d9", "Hidalgo" = "#30b8c2", "México" ="#d47304", "Morelos" = "#398c20", "Puebla" ="#e8e52e", "Querétaro"="#c70202", "Tlaxcala" = "#334eb8")
chordDiagram(matriz_mega, grid.col = grid.col3)
## Note: The second link end is drawn out of sector 'México'.
## Note: The second link end is drawn out of sector 'Morelos'.
## Note: The second link end is drawn out of sector 'Tlaxcala'.
Hacemos algunos ajustes de transparencia, ancho y color de la línea del borde, así como el nombre de los sectores (entidades)
chordDiagram(
x = matriz_mega, #datos
grid.col = grid.col3, #colores
transparency = 0.25, #transparencia
directional = 1, #dirección
direction.type = c("arrows", "diffHeight"), #Tipo de dirección y ancho
diffHeight = 0, # Elimina un espacio innecesario
annotationTrack = "grid", #nombre de sectores
annotationTrackHeight = c(0.07, 0.07), #altura del espacio para nombres
link.arr.type = "big.arrow",
link.largest.ontop = TRUE,
link.lwd = 0.8, link.lty = 1, #Ancho y tipo de líneas
link.border = "gray50") #Color de linea
## Note: The second link end is drawn out of sector 'México'.
## Note: The second link end is drawn out of sector 'Morelos'.
## Note: The second link end is drawn out of sector 'Tlaxcala'.
for(si in get.all.sector.index()) {
xlim = get.cell.meta.data("xlim", sector.index = si, track.index = 1)
ylim = get.cell.meta.data("ylim", sector.index = si, track.index = 1)
circos.text(mean(xlim), mean(ylim), si, sector.index = si, track.index = 1,
facing = "bending", cex= 0.6, col = "gray90")
}
Finalmente con colores de la librería viridis
circos.clear()
circos.par(start.degree = 90, gap.degree = 4, track.margin = c(-0.1, 0.1), points.overflow.warning = FALSE)
par(mar = rep(0, 4))
# color palette
mycolor2 <- viridis(7, alpha = 1, begin = 0, end = 1, option = "D")
mycolor2 <- mycolor[sample(1:7)]
# Base plot
chordDiagram(
x = matriz_mega,
grid.col = mycolor2,
transparency = 0.25,
directional = 1,
direction.type = c("arrows", "diffHeight"),
diffHeight = -0.03,
annotationTrack = "grid",
annotationTrackHeight = c(0.05, 0.1),
link.arr.type = "big.arrow",
link.sort = TRUE,
link.largest.ontop = TRUE)
## Note: The second link end is drawn out of sector 'Tlaxcala'.
## Note: The second link end is drawn out of sector 'Morelos'.
## Note: The second link end is drawn out of sector 'México'.
# Add text and axis
circos.trackPlotRegion(
track.index = 1,
bg.border = NA,
panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
sector.index = get.cell.meta.data("sector.index")
# Add names to the sector.
circos.text(
x = mean(xlim),
y = 3.2,
labels = sector.index,
facing = "bending",
cex = 0.7,
col = "gray25"
)
}
)
Como son menos datos y es una zona dinámica, se aprecian mucho mejor los flujos de migración.
Pero existe una infinidad de posibilidades con estos datos, como ver los flujos entre la zona fronteriza, las zonas turísticas, el sur del país e incluso desde otros países. Además este tipo de gráficas de pueden utilizar en aspectos económicos como flujo de mercancías, políticos como desplazados y refugiados, históricos como migraciones, entre muchos otros.
También existe una gran cantidad de prosibilidades para las gráficas de cuerdas, como resaltar ciertos flujos o que al pasar el cursor, exista un resalte de la información, pero eso será tema de otra ocasión.