Datos Espaciales en R

Análisis espacial

Verónica Andreo

Instituto Gulich

CONICET

Pablo Paccioretti

Instituto Gulich

UNC - CONICET

Temas

  1. Introducción a R
  2. Manejo de datos espaciales con sf
    • Lectura de archivos de diferentes formatos
      • Base de datos de texto (data.frame)
      • Geopackage
      • Shapefile
    • Manejo de objetos sf
    • Proyección y reproyección
  1. Manejo de bases de datos dplyr
  2. Visualización
    • Paquete ggplot2
    • Paquete tmap

Esta presentación y los datos están disponibles en

https://veroandreo.github.io/analisis_espacial/

GitHub

  • GitHub es una plataforma de desarrollo colaborativo para alojar proyectos utilizando el sistema de control de versiones Git

  • El código de los proyectos alojados en GitHub se almacena típicamente de forma pública

  • En 2018, Microsoft compró GitHub por 7.500 millones de dólares

Una vez descargado, lo extraemos en una carpeta. Abrimos con RStudio el proyecto llamado VisualizaciónDatosEspaciales.Rproj

Links de descarga

R e Interfaz con RStudio

Sintaxis

  • Los # indican comentarios en el código, todo lo que está a la derecha de este símbolo no será ejecutado.
  • Si deseamos guardar un resultado de una función en un objeto, debemos utilizar la función de asignación <-.
  • Argumentos de una functión se especifican entre paréntesis y están separados por coma: NombreFuncion(arg1, arg2).
  • R distingue mayúsculas y minúsculas.
  • Caracteres especiales (espacios, tildes, signos) son reemplazados por punto (.) en nombres de columnas cuando se usan funciones del paquete base.
  • Se recomienda evitar el uso de tildes, ñ, símbolos matemáticos para nombres de los niveles de factores, columnas y objetos.

Ejemplos de código

2 + 2
normalAleatorio <- rnorm(10, mean = 0, sd = 1)
normalAleatorio
## [1] 4
##  [1] -1.02292593 -0.57989690  2.17369173  0.23261128  0.42604378 -0.93304683
##  [7]  0.22128698 -0.04385321 -0.80428940  0.79975458

Datos espaciales

R-espacial

  • Hay numerosos paquetes para el manejo de datos espaciales geoR, gstat, spdep, sf, stars, terra, entre otros.
  • Los primeros procedimientos espaciales de R se originaron en el lenguaje S, en la década del 90 (Bivand y Gebhardt 2000).
  • A partir del 2000, R ofrece paquetes que posibilitan el tratamiento de datos espaciales a través de diversos métodos. Algunos de ellos todavía se utilizan.
  • El paquete sf se basa en su predecesor sp.

Datos espaciales en R

  • Los datos vectoriales, usando puntos, líneas y polígonos, permiten representar superficies
  • Los datos tipo raster divide la superficie en celdas (pixeles) de tamaño constante

Paquete sf

Simple features es una manera estandarizada de codificar, en computadoras, datos vectoriales (puntos , lineas y polígonos )

El paquete sf implementa simple features en R y conserva las mismas capacidades para el manejo de datos vectoriales como los paquetes sp, rgeos y rgdal (Pebesma 2018)

El manejo de objetos espaciales se convirtió en un proceso más simple y acorde a la lógica de programación de R

Paquete sf

  • El paquete sf permite el análisis y el manejo de archivos con datos espaciales

  • Los objetos espaciales sf están almacenados como data.frame, donde los datos geográficos ocupan una columna especial (geometry list-column)

  • A partir de un objeto sf se puede obtener un data.frame, el cual tendrá una columna del tipo lista con la posición geográfica

  • Las funciones del paquete comienzan con st_

  • Los objetos espaciales sf pueden ser tratados como data.frame en la mayoría de las operaciones

Paquete terra

  • Es compatible con objetos de tipo raster en R
  • Provee numerosas funciones para crear, leer, exportar, manipular y procesar datos de tipo raster
  • Permite trabajar con raster de dimensiones muy grandes para ser almacenados en la memoria RAM
  • Cada celda del archivo raster, puede contener un único valor (numérico o categórico)
  • Se pueden agrupar más de una capa en un mismo raster

Sistema de coordenadas de referencia

  • Define cómo los elementos espaciales de los datos se relacionan con la superficie terrestre
  • Pueden ser
    • Sistemas de coordenadas geográficas: Identifica cualquier punto de la superficie terrestre utilizando Latitud y Longitud
    • Proyecciones: Basados en coordenadas cartesianas en una superficie plana (Ejemplo UTM)

Manos a la obra

Lectura de archivos

  • Desde archivo de texto (Muestreo de Suelo de la Provincia de Córdoba)
  • Desde un archivo Shapefile (.shp) (Cuencas de la Provincia de Córdoba)
  • Desde un archivo GeoPackage (.gpkg) (Departamentos de la Provincia de Córdoba)

Lectura de archivo de texto

muestreo <- read.table("datos/MuestreoSuelo.txt", header = T, sep = "\t")
muestreo
##           Xt      Yt Limo   CC    K
## 1   603163.6 6576899 67.0 29.3 2.30
## 2   596537.1 6390518 66.0 28.9 2.02
## 3   595665.5 6380484 62.9 27.5 1.38
## 4   601138.5 6353446 57.4 25.4 1.60
## 5   601798.1 6344096 61.1 25.3 1.36
## 6   587501.2 6615272 65.3 25.4 2.40
## 7   589808.2 6593001 62.6 25.7 2.30
## 8   585406.5 6575712 69.3 23.4 1.81
## 9   584319.9 6552571 64.6 25.1 3.00
## 10  582795.8 6536823 59.0 33.5 2.33
## 11  578393.8 6514830 68.5 29.3 2.24
## 12  583401.3 6415459 73.7 21.8 2.30
## 13  584191.3 6397971 59.8 25.9 1.99
## 14  581920.4 6376827 61.0 24.7 1.78
## 15  577542.6 6355542 61.8 23.6 1.93
## 16  584591.7 6335074 56.7 28.0 1.70
## 17  580626.0 6317237 44.8 25.4 2.10
## 18  562987.4 6573479 63.1 25.0 2.00
## 19  566036.4 6556137 61.5 25.3 2.30
## 20  562334.3 6536965 61.1 24.0 2.38
## 21  559369.8 6522722 64.4 25.1 2.24
## 22  560282.0 6498671 56.3 22.6 1.43
## 23  560549.5 6488513 55.4 25.8 2.17
## 24  564983.2 6460704 67.8 25.2 2.30
## 25  562125.9 6417162 65.6 27.3 2.31
## 26  562506.2 6396998 64.6 28.2 2.14
## 27  561288.0 6377057 59.5 22.6 2.07
## 28  558959.4 6356407 53.2 25.9 1.92
## 29  565136.4 6336920 52.3 24.4 2.05
## 30  561075.5 6317870 55.1 26.6 1.83
## 31  560453.6 6296711 45.4 18.6 1.60
## 32  561826.7 6277806 39.5 18.4 2.00
## 33  540132.5 6572395 60.2 29.8 1.80
## 34  540066.3 6554923 47.9 19.0 1.70
## 35  540779.8 6533415 63.8 22.8 2.50
## 36  540148.3 6525651 62.4 22.9 2.00
## 37  544374.1 6494569 66.2 28.5 2.43
## 38  538352.2 6481364 53.0 23.5 2.10
## 39  537104.6 6461968 64.5 26.5 2.58
## 40  532245.0 6442189 89.1 30.0 3.02
## 41  541745.0 6421084 51.8 20.9 1.73
## 42  539590.4 6394002 47.3 17.9 1.86
## 43  548155.4 6373990 54.0 20.1 1.96
## 44  540549.2 6359775 52.1 20.4 2.02
## 45  545162.9 6334934 51.7 20.7 1.94
## 46  543884.1 6320334 44.1 18.7 3.30
## 47  541060.1 6295328 41.4 19.2 1.72
## 48  534777.0 6267747 20.1 12.7 1.75
## 49  548234.6 6259178 22.5 15.7 1.75
## 50  517735.0 6571859 61.3 21.9 2.80
## 51  521452.9 6557077 54.7 20.0 1.88
## 52  518981.7 6539152 56.4 27.7 1.90
## 53  516398.8 6523475 62.2 21.4 2.30
## 54  526721.8 6505980 64.3 22.6 2.20
## 55  521566.0 6479408 51.6 18.7 1.70
## 56  517747.8 6451336 64.5 25.2 2.30
## 57  520817.7 6423081 63.6 27.7 3.30
## 58  521616.1 6394127 58.0 23.8 2.30
## 59  523663.2 6374580 54.3 20.9 2.50
## 60  522161.5 6361886 54.5 18.8 2.30
## 61  523948.5 6338317 46.8 17.6 2.40
## 62  522520.0 6315974 43.7 17.6 2.10
## 63  521852.5 6296957 28.6 12.8 2.40
## 64  527007.2 6280271 25.3 12.9 2.10
## 65  515660.9 6259661 19.2 17.4 2.80
## 66  521364.1 6242214 43.3 21.4 1.80
## 67  519430.2 6208790 30.1 20.2 1.30
## 68  497504.3 6595468 69.9 20.9 2.60
## 69  498859.5 6582924 48.7 28.4 2.30
## 70  496547.8 6554849 61.2 22.3 2.70
## 71  502725.1 6522890 43.8 18.4 2.10
## 72  504966.4 6496754 61.7 20.7 2.20
## 73  493626.2 6469272 60.6 23.3 2.70
## 74  503024.7 6459416 88.1 18.7 2.40
## 75  491398.7 6442386 61.8 21.8 2.20
## 76  501034.0 6417872 63.0 20.0 2.40
## 77  503837.2 6399237 57.3 33.0 2.60
## 78  500936.9 6377536 55.9 21.8 2.20
## 79  494748.6 6356124 49.6 17.7 2.20
## 80  500781.0 6333918 44.5 20.0 2.00
## 81  490612.0 6315769 36.2 15.3 2.24
## 82  499572.0 6292384 22.8 14.0 2.10
## 83  505459.8 6279687 16.7 12.7 1.59
## 84  495630.8 6254221 18.8 13.5 1.68
## 85  502250.4 6228812 31.7 18.1 2.36
## 86  500274.5 6213317 35.9 16.0 1.40
## 87  501314.0 6200115 30.6 16.2 2.10
## 88  470472.3 6684993 57.8 24.3 2.20
## 89  467093.8 6665904 47.0 17.9 2.80
## 90  480380.6 6596978 25.3 11.9 1.50
## 91  478336.1 6581409 55.4 25.7 3.20
## 92  478088.6 6555574 59.8 20.8 2.16
## 93  472449.7 6531218 62.7 20.3 2.11
## 94  479440.8 6520630 30.7 16.3 1.00
## 95  480565.5 6497231 60.9 19.9 2.30
## 96  481351.8 6454471 51.6 25.7 1.75
## 97  480685.6 6433792 61.5 21.4 2.70
## 98  480716.9 6417424 55.2 21.6 2.70
## 99  477386.8 6397107 52.0 21.3 2.40
## 100 477023.6 6378135 57.6 17.5 2.60
## 101 478417.9 6357823 51.4 15.7 2.40
## 102 480871.4 6337608 42.9 13.7 2.20
## 103 472700.4 6317987 14.9 11.0 1.49
## 104 481955.4 6299139 43.8 17.2 1.80
## 105 481424.9 6268437 24.7 14.9 2.00
## 106 476134.6 6246140 20.0 12.7 1.96
## 107 487791.2 6235224 19.2 10.1 3.10
## 108 479213.4 6220087 41.7 17.5 1.60
## 109 478163.3 6197931 15.7  9.6 2.10
## 110 452453.0 6685685 59.2 24.3 2.80
## 111 454630.4 6650994 57.4 23.2 2.00
## 112 454257.6 6632302 31.3 12.6 1.80
## 113 463017.2 6617131 53.0 25.3 2.40
## 114 459804.0 6596920 39.9 13.5 1.74
## 115 459951.2 6581356 44.3 19.6 2.10
## 116 462475.7 6557023 35.2 17.9 2.26
## 117 456426.2 6528027 58.4 21.7 2.77
## 118 462239.5 6500271 58.6 19.7 2.40
## 119 457980.5 6478448 62.6 19.0 2.78
## 120 460337.2 6457270 59.2 17.8 3.00
## 121 460415.0 6437318 48.8 14.9 2.70
## 122 459339.5 6416020 50.3 15.3 2.10
## 123 457447.1 6401523 54.8 16.8 3.40
## 124 460815.3 6380176 39.9 15.2 4.80
## 125 465851.6 6355547 40.0 12.6 2.30
## 126 464229.4 6338212 37.2 13.4 2.10
## 127 450953.0 6311663 31.4 17.7 1.74
## 128 465263.7 6296646 40.4 14.9 1.97
## 129 460321.8 6275948 22.8 13.0 1.78
## 130 456056.2 6258558 23.7 11.5 1.46
## 131 459850.7 6238129 36.8 10.9 1.74
## 132 460984.6 6218295 26.6 13.2 2.40
## 133 460561.6 6198268 27.7 14.5 1.80
## 134 456152.1 6175430 28.4 14.5 1.53
## 135 459156.5 6159880 32.4 15.9 1.71
## 136 448405.0 6145931 46.8 26.7 1.90
## 137 429559.3 6713097 35.3 20.9 1.40
## 138 431144.2 6693667 56.2 27.3 1.60
## 139 441061.9 6675047 61.5 22.8 2.40
## 140 433488.8 6656236 64.8 24.7 2.30
## 141 430584.4 6631845 59.9 23.5 2.20
## 142 439114.4 6616771 63.7 23.2 2.10
## 143 439227.2 6596823 58.9 22.5 3.10
## 144 444384.3 6572176 58.0 23.0 2.48
## 145 439454.5 6556926 60.1 23.2 2.45
## 146 439488.0 6534813 61.5 21.9 2.30
## 147 442482.7 6521239 59.7 19.8 2.28
## 148 437738.5 6502293 58.5 20.7 2.40
## 149 437197.4 6476251 53.4 18.8 2.34
## 150 440689.2 6459394 53.4 18.1 2.01
## 151 440150.9 6437219 47.4 26.7 1.70
## 152 436267.8 6422024 52.5 20.6 1.90
## 153 443077.9 6398613 45.9 18.9 3.20
## 154 435863.8 6379223 38.4 13.1 1.90
## 155 446603.0 6357883  0.0 12.6 1.67
## 156 442929.0 6343522 26.5 12.1 1.75
## 157 439491.9 6318077 12.8 10.0 1.33
## 158 431151.7 6297512 20.0 14.9 1.95
## 159 440484.8 6275979 19.8 10.8 1.47
## 160 440098.6 6250709 30.1 12.1 1.45
## 161 443317.3 6244373 12.3 12.5 1.64
## 162 440967.5 6227407 29.3 16.2 1.50
## 163 438685.1 6206640 34.9 19.0 1.60
## 164 440748.3 6181170 24.4 15.7 1.60
## 165 435022.6 6151497 20.9 13.8 1.60
## 166 445299.8 6133188 28.7 17.9 1.70
## 167 409646.2 6716651 33.7 19.3 1.40
## 168 414484.4 6691598 26.9 13.2 1.58
## 169 418050.8 6676478 43.9 22.1 1.30
## 170 414909.6 6656061 58.0 21.9 2.20
## 171 415617.6 6642029 56.1 20.6 2.00
## 172 423666.9 6616209 58.0 25.9 2.50
## 173 418240.5 6593812 54.5 23.7 1.90
## 174 414895.0 6575416 61.9 22.4 2.28
## 175 408415.6 6559531 58.1 26.5 2.30
## 176 419639.8 6535327 62.4 21.1 2.00
## 177 418820.7 6517895 57.7 19.5 2.50
## 178 419416.8 6496936 53.1 21.7 2.50
## 179 420262.1 6480316 59.2 19.8 2.10
## 180 419729.1 6457032 55.6 15.4 1.70
## 181 419886.4 6437079  0.0 10.2 0.80
## 182 422555.7 6416999 46.6 20.2 1.50
## 183 424187.6 6394253 36.1 17.8 2.02
## 184 420123.2 6377094 35.1 19.1 1.70
## 185 416997.7 6363302 19.9 10.0 1.42
## 186 425171.0 6344753 22.0 13.9 2.40
## 187 417917.2 6326746 38.5 22.6 2.91
## 188 423547.6 6312202 19.8 12.7 1.54
## 189 420675.5 6277073 26.3 13.1 1.87
## 190 432630.4 6256211 20.8 13.3 1.72
## 191 415059.8 6233151 28.7 17.1 1.70
## 192 415498.8 6218453 18.4 12.2 1.70
## 193 413075.1 6197490 15.5 12.4 1.50
## 194 421888.2 6180592 18.2 13.9 1.50
## 195 414970.2 6156712 14.8 12.2 1.60
## 196 415114.3 6136351 24.6 15.1 2.20
## 197 393546.6 6719911 15.9 19.3 1.00
## 198 401410.3 6690743   NA   NA   NA
## 199 400509.7 6673860 35.8 18.2 1.00
## 200 388211.0 6657912 22.9  9.6 0.70
## 201 397694.8 6636409 55.4 20.2 1.70
## 202 401699.9 6616496 49.4 19.3 2.49
## 203 398072.1 6596511 49.0 20.4 1.90
## 204 398262.3 6576561 42.4 16.4 1.30
## 205 391757.1 6558627 56.3 24.5 2.10
## 206 399062.8 6541124 59.0 19.2 2.10
## 207 402114.3 6516158 59.2 22.7 2.10
## 208 399184.9 6498206 53.8 19.0 1.80
## 209 393818.3 6473953 60.0 18.5 2.58
## 210 390997.4 6456296 44.4 16.6 1.80
## 211 399621.5 6436898 30.8 11.6 1.40
## 212 398740.7 6419518 46.8 18.9 1.72
## 213 406077.5 6399415 39.3 16.3 1.73
## 214 401547.6 6373100  9.6 10.1 1.36
## 215 401702.3 6355989 20.6 11.5 1.30
## 216 406179.8 6343827 18.8 10.8 1.53
## 217 407790.9 6317412 20.6 11.9 1.57
## 218 409014.6 6295734 26.7 12.7 1.77
## 219 401905.3 6279374 24.7 15.3 1.80
## 220 401472.9 6255903 26.0 17.7 2.20
## 221 398589.2 6235905 29.3 13.6 1.90
## 222 402509.3 6212629 23.2 16.1 1.90
## 223 393126.7 6195885 13.6 12.0 1.50
## 224 400762.9 6181513 19.7 14.5 1.90
## 225 394375.2 6156445 18.9 11.3 1.60
## 226 400352.3 6138834 23.2 10.9 1.80
## 227 375837.0 6714323 49.2 26.6 1.10
## 228 381213.8 6709304 38.3 19.0 1.10
## 229 365386.8 6695978 51.6 26.4 1.90
## 230 388733.8 6667326   NA   NA   NA
## 231 377040.0 6636195 35.0 19.6 1.80
## 232 382613.1 6619021 49.3 19.7 1.80
## 233 379647.2 6574478 20.7 16.9 1.30
## 234 377952.0 6556394 20.5 15.1 0.60
## 235 379858.9 6542664 53.1 23.0 2.18
## 236 379912.8 6513835 60.7 25.1 2.50
## 237 378648.6 6496538 67.4 26.8 2.50
## 238 378883.2 6476585 54.9 23.1 2.10
## 239 373300.2 6454149 59.8 20.8 1.70
## 240 379356.0 6436677 53.6 26.5 2.00
## 241 376539.5 6419165 15.8  6.3 0.50
## 242 374614.2 6394682 36.1 15.9 1.50
## 243 378122.0 6374189 23.1 11.0 1.60
## 244 371612.3 6361513 40.0 18.9 2.30
## 245 383588.6 6341233 41.7 23.9 2.90
## 246 374332.4 6317590 31.9 18.7 2.30
## 247 381633.0 6292313 26.4 10.0 2.00
## 248 384814.0 6282948 15.2  8.7 1.60
## 249 377971.7 6258673 11.5  8.9 1.80
## 250 378353.9 6241497 18.8 10.2 1.70
## 251 385668.5 6223915 15.6 10.1 1.30
## 252 372920.8 6201697 10.7  9.7 1.50
## 253 373822.7 6168505 10.6 12.7 2.40
## 254 374283.5 6155857 17.6 11.4 2.00
## 255 379627.0 6134719 58.2 15.2 2.20
## 256 348711.8 6711924 15.4 15.6 0.90
## 257 358202.9 6708195 31.1 13.7 1.40
## 258 362072.5 6681197 29.0 17.2 0.90
## 259 355738.7 6657258 27.9 13.6 1.40
## 260 356043.7 6636299 29.0 19.9 1.00
## 261 357028.1 6627659 41.5 22.8 1.70
## 262 357836.5 6595032 26.6 27.8 1.09
## 263 357181.3 6576089 19.1 20.0 0.70
## 264 357460.4 6556071 20.1 16.1 0.40
## 265 357799.4 6535105 15.5 15.3 0.50
## 266 363571.9 6515526 50.8 21.7 2.00
## 267 366450.7 6494150 32.8 17.6 1.10
## 268 358491.9 6479635 48.7 21.5 1.40
## 269 364859.8 6456431 48.0 16.9 1.70
## 270 352374.6 6437236 47.2 22.2 1.70
## 271 360020.4 6412716 32.2 14.3 2.20
## 272 360639.9 6397543 42.5 14.2 1.40
## 273 363104.2 6380446 46.1 13.5 1.40
## 274 363949.4 6366384 36.6 13.2 1.50
## 275 360297.2 6339369 36.3 20.8 2.40
## 276 358906.9 6318191 22.9 12.8 2.40
## 277 368023.8 6297300 31.9 15.2 3.00
## 278 356796.3 6281601 24.7 15.1 1.60
## 279 360840.7 6258420 26.6 16.1 1.80
## 280 357728.1 6243261 11.6  8.2 1.10
## 281 365059.0 6217702  4.0  5.5 1.20
## 282 372915.4 6201693 12.4  7.2 1.50
## 283 369232.8 6178825 10.5 10.2 1.90
## 284 354127.0 6154878 15.4  8.4 2.00
## 285 364634.4 6141008 10.6  7.7 2.20
## 286 322034.1 6722199 44.0 27.3 1.90
## 287 336988.4 6702457 33.9 13.2 1.60
## 288 342934.9 6678617 21.0  8.4 1.10
## 289 333942.3 6663125 39.0 20.5 1.85
## 290 339487.4 6636141 30.0 17.8 1.40
## 291 351274.0 6477363 58.2 34.0 1.90
## 292 340122.0 6459510 52.3 26.7 0.80
## 293 358358.8 6422919 48.1 14.2 2.10
## 294 348091.4 6386836 47.9 13.1 1.90
## 295 338135.2 6376681 43.4 20.9 1.70
## 296 335929.7 6354151 49.1 30.6 2.50
## 297 338757.8 6338937 28.2 18.3 2.00
## 298 348477.5 6320510 14.6  9.3 1.50
## 299 343471.4 6292974 30.3 14.9 1.50
## 300 331109.7 6247386  8.8  7.5 1.10
## 301 342413.3 6226849 11.2  8.6 1.40
## 302 342963.0 6193915  9.9  7.1 1.50
## 303 343616.1 6170952 13.7  5.0 1.50
## 304 336324.5 6164347  0.0  6.6 1.70
## 305 344720.9 6134254  0.0 12.1 2.10
## 306 314936.8 6654862 26.7 10.3 1.10
## 307 326153.8 6628397 28.4 14.4 1.30
## 308 315026.9 6615022 18.0 10.2 1.29
## 309 318722.8 6592813 22.9 12.7 1.00
## 310 302508.5 6573027 57.8 27.8 3.30
## 311 310568.5 6517139 40.4 22.0 0.80
## 312 316152.5 6474608 46.1  9.6 1.80
## 313 304247.8 6459885 28.3 13.2 2.40
## 314 307888.3 6436238 36.9 15.0 0.80
## 315 326290.2 6358537 52.1 24.2 1.50
## 316 323251.7 6333011 17.7 11.7 0.60
## 317 323107.8 6317898 13.4 11.7 1.60
## 318 323918.5 6296467 13.4  9.0 1.20
## 319 313421.1 6284488 12.8  9.6 1.70
## 320 311319.3 6250934  9.2  6.0 1.30
## 321 316141.0 6234887 17.5 10.9 1.40
## 322 312199.4 6218220 12.2  8.5 1.70
## 323 322774.6 6196569  7.7  5.3 1.30
## 324 313315.5 6173792  7.1  6.8 1.40
## 325 314626.1 6153624  5.1  6.9 1.20
## 326 314547.3 6135107 23.5 12.2 1.50
## 327 303239.8 6620640 21.5 14.4 1.40
## 328 292241.2 6594051 29.3 16.0 2.00
## 329 304823.8 6586070 38.9 15.7 1.21
## 330 299754.1 6554098 41.7 15.3 0.86
## 331 299158.8 6536651 33.4 17.3 1.10
## 332 292274.0 6516662 14.2  6.9 1.03
## 333 300315.6 6496947 56.8 22.6 1.10
## 334 295007.2 6475754 47.8 19.3 1.20
## 335 295427.5 6437040 28.8 14.4 1.50
## 336 300698.5 6315618 11.1  8.4 1.10
## 337 256689.0 6610529 39.0 12.5 1.10
## 338 271612.2 6610072 33.9 14.2 1.10
## 339 278760.3 6590394 31.3 16.4 1.50
## 340 273995.8 6573165 25.9 11.3 0.60
## 341 284724.4 6544882 55.3 21.1 0.60
## 342 281465.5 6528077 18.7  9.1 0.60
## 343 270532.2 6513493 29.3 14.1 1.00
## 344 281067.8 6495186 28.0 10.0 1.10
## 345 270093.9 6473571 46.2 17.1 2.10
## 346 277578.3 6454923 29.7 10.5 0.80
## 347 257921.1 6610371 33.0 14.3 1.60
## 348 246082.7 6589469 38.5 17.1 1.50
## 349 250409.8 6572978 30.6 10.2 1.20
## 350 235888.3 6553601 40.2 14.0 1.30
## 351 251686.1 6530851 26.3 11.5 0.90
## 352 251673.6 6518741 23.8 10.5 0.80
## 353 260311.3 6503994 31.3 16.1 1.40
## 354 244261.6 6468475 33.2 17.0 2.70
## 355 259768.2 6551776 15.0  7.3 1.30

Paquete ggplot2

Idividualmente se especifican partes del gráfico. Luego estas partes se combinan para obtener el gráfico completo. Estas partes son:

  • Datos
  • Mapeo estético (aesthetic mapping)
  • Objetos geométricos (geometric object)
  • Transformaciones estadísticas (statistical transformations)
  • Escalas (scales)
  • Sistema de coordenadas (coordinate system)
  • Ajustes de posición (position adjustments)
  • Particiones (faceting)

Gráficos usando ggplot2

ggplot()

Gráficos usando ggplot2

ggplot(muestreo)

Gráficos usando ggplot2

ggplot(muestreo, aes(Limo))

Gráficos usando ggplot2

ggplot(muestreo, aes(Limo)) +
  geom_histogram()

Paquete dplyr

dplyr fue diseñado para la manipulación y transformación de datos de una manera sencilla y eficiente.

Manipulación de datos verbales: dplyr se basa en “verbos” de manipulación de datos, como filter, mutate, summarize, y group_by, lo que simplifica la manipulación de datos en pasos lógicos.

Manejo de bases de datos

library(dplyr)

muestreo |>
  mutate(mediaLimo = mean(Limo, na.rm = TRUE))
##           Xt      Yt Limo   CC    K mediaLimo
## 1   603163.6 6576899 67.0 29.3 2.30  39.58867
## 2   596537.1 6390518 66.0 28.9 2.02  39.58867
## 3   595665.5 6380484 62.9 27.5 1.38  39.58867
## 4   601138.5 6353446 57.4 25.4 1.60  39.58867
## 5   601798.1 6344096 61.1 25.3 1.36  39.58867
## 6   587501.2 6615272 65.3 25.4 2.40  39.58867
## 7   589808.2 6593001 62.6 25.7 2.30  39.58867
## 8   585406.5 6575712 69.3 23.4 1.81  39.58867
## 9   584319.9 6552571 64.6 25.1 3.00  39.58867
## 10  582795.8 6536823 59.0 33.5 2.33  39.58867
## 11  578393.8 6514830 68.5 29.3 2.24  39.58867
## 12  583401.3 6415459 73.7 21.8 2.30  39.58867
## 13  584191.3 6397971 59.8 25.9 1.99  39.58867
## 14  581920.4 6376827 61.0 24.7 1.78  39.58867
## 15  577542.6 6355542 61.8 23.6 1.93  39.58867
## 16  584591.7 6335074 56.7 28.0 1.70  39.58867
## 17  580626.0 6317237 44.8 25.4 2.10  39.58867
## 18  562987.4 6573479 63.1 25.0 2.00  39.58867
## 19  566036.4 6556137 61.5 25.3 2.30  39.58867
## 20  562334.3 6536965 61.1 24.0 2.38  39.58867
## 21  559369.8 6522722 64.4 25.1 2.24  39.58867
## 22  560282.0 6498671 56.3 22.6 1.43  39.58867
## 23  560549.5 6488513 55.4 25.8 2.17  39.58867
## 24  564983.2 6460704 67.8 25.2 2.30  39.58867
## 25  562125.9 6417162 65.6 27.3 2.31  39.58867
## 26  562506.2 6396998 64.6 28.2 2.14  39.58867
## 27  561288.0 6377057 59.5 22.6 2.07  39.58867
## 28  558959.4 6356407 53.2 25.9 1.92  39.58867
## 29  565136.4 6336920 52.3 24.4 2.05  39.58867
## 30  561075.5 6317870 55.1 26.6 1.83  39.58867
## 31  560453.6 6296711 45.4 18.6 1.60  39.58867
## 32  561826.7 6277806 39.5 18.4 2.00  39.58867
## 33  540132.5 6572395 60.2 29.8 1.80  39.58867
## 34  540066.3 6554923 47.9 19.0 1.70  39.58867
## 35  540779.8 6533415 63.8 22.8 2.50  39.58867
## 36  540148.3 6525651 62.4 22.9 2.00  39.58867
## 37  544374.1 6494569 66.2 28.5 2.43  39.58867
## 38  538352.2 6481364 53.0 23.5 2.10  39.58867
## 39  537104.6 6461968 64.5 26.5 2.58  39.58867
## 40  532245.0 6442189 89.1 30.0 3.02  39.58867
## 41  541745.0 6421084 51.8 20.9 1.73  39.58867
## 42  539590.4 6394002 47.3 17.9 1.86  39.58867
## 43  548155.4 6373990 54.0 20.1 1.96  39.58867
## 44  540549.2 6359775 52.1 20.4 2.02  39.58867
## 45  545162.9 6334934 51.7 20.7 1.94  39.58867
## 46  543884.1 6320334 44.1 18.7 3.30  39.58867
## 47  541060.1 6295328 41.4 19.2 1.72  39.58867
## 48  534777.0 6267747 20.1 12.7 1.75  39.58867
## 49  548234.6 6259178 22.5 15.7 1.75  39.58867
## 50  517735.0 6571859 61.3 21.9 2.80  39.58867
## 51  521452.9 6557077 54.7 20.0 1.88  39.58867
## 52  518981.7 6539152 56.4 27.7 1.90  39.58867
## 53  516398.8 6523475 62.2 21.4 2.30  39.58867
## 54  526721.8 6505980 64.3 22.6 2.20  39.58867
## 55  521566.0 6479408 51.6 18.7 1.70  39.58867
## 56  517747.8 6451336 64.5 25.2 2.30  39.58867
## 57  520817.7 6423081 63.6 27.7 3.30  39.58867
## 58  521616.1 6394127 58.0 23.8 2.30  39.58867
## 59  523663.2 6374580 54.3 20.9 2.50  39.58867
## 60  522161.5 6361886 54.5 18.8 2.30  39.58867
## 61  523948.5 6338317 46.8 17.6 2.40  39.58867
## 62  522520.0 6315974 43.7 17.6 2.10  39.58867
## 63  521852.5 6296957 28.6 12.8 2.40  39.58867
## 64  527007.2 6280271 25.3 12.9 2.10  39.58867
## 65  515660.9 6259661 19.2 17.4 2.80  39.58867
## 66  521364.1 6242214 43.3 21.4 1.80  39.58867
## 67  519430.2 6208790 30.1 20.2 1.30  39.58867
## 68  497504.3 6595468 69.9 20.9 2.60  39.58867
## 69  498859.5 6582924 48.7 28.4 2.30  39.58867
## 70  496547.8 6554849 61.2 22.3 2.70  39.58867
## 71  502725.1 6522890 43.8 18.4 2.10  39.58867
## 72  504966.4 6496754 61.7 20.7 2.20  39.58867
## 73  493626.2 6469272 60.6 23.3 2.70  39.58867
## 74  503024.7 6459416 88.1 18.7 2.40  39.58867
## 75  491398.7 6442386 61.8 21.8 2.20  39.58867
## 76  501034.0 6417872 63.0 20.0 2.40  39.58867
## 77  503837.2 6399237 57.3 33.0 2.60  39.58867
## 78  500936.9 6377536 55.9 21.8 2.20  39.58867
## 79  494748.6 6356124 49.6 17.7 2.20  39.58867
## 80  500781.0 6333918 44.5 20.0 2.00  39.58867
## 81  490612.0 6315769 36.2 15.3 2.24  39.58867
## 82  499572.0 6292384 22.8 14.0 2.10  39.58867
## 83  505459.8 6279687 16.7 12.7 1.59  39.58867
## 84  495630.8 6254221 18.8 13.5 1.68  39.58867
## 85  502250.4 6228812 31.7 18.1 2.36  39.58867
## 86  500274.5 6213317 35.9 16.0 1.40  39.58867
## 87  501314.0 6200115 30.6 16.2 2.10  39.58867
## 88  470472.3 6684993 57.8 24.3 2.20  39.58867
## 89  467093.8 6665904 47.0 17.9 2.80  39.58867
## 90  480380.6 6596978 25.3 11.9 1.50  39.58867
## 91  478336.1 6581409 55.4 25.7 3.20  39.58867
## 92  478088.6 6555574 59.8 20.8 2.16  39.58867
## 93  472449.7 6531218 62.7 20.3 2.11  39.58867
## 94  479440.8 6520630 30.7 16.3 1.00  39.58867
## 95  480565.5 6497231 60.9 19.9 2.30  39.58867
## 96  481351.8 6454471 51.6 25.7 1.75  39.58867
## 97  480685.6 6433792 61.5 21.4 2.70  39.58867
## 98  480716.9 6417424 55.2 21.6 2.70  39.58867
## 99  477386.8 6397107 52.0 21.3 2.40  39.58867
## 100 477023.6 6378135 57.6 17.5 2.60  39.58867
## 101 478417.9 6357823 51.4 15.7 2.40  39.58867
## 102 480871.4 6337608 42.9 13.7 2.20  39.58867
## 103 472700.4 6317987 14.9 11.0 1.49  39.58867
## 104 481955.4 6299139 43.8 17.2 1.80  39.58867
## 105 481424.9 6268437 24.7 14.9 2.00  39.58867
## 106 476134.6 6246140 20.0 12.7 1.96  39.58867
## 107 487791.2 6235224 19.2 10.1 3.10  39.58867
## 108 479213.4 6220087 41.7 17.5 1.60  39.58867
## 109 478163.3 6197931 15.7  9.6 2.10  39.58867
## 110 452453.0 6685685 59.2 24.3 2.80  39.58867
## 111 454630.4 6650994 57.4 23.2 2.00  39.58867
## 112 454257.6 6632302 31.3 12.6 1.80  39.58867
## 113 463017.2 6617131 53.0 25.3 2.40  39.58867
## 114 459804.0 6596920 39.9 13.5 1.74  39.58867
## 115 459951.2 6581356 44.3 19.6 2.10  39.58867
## 116 462475.7 6557023 35.2 17.9 2.26  39.58867
## 117 456426.2 6528027 58.4 21.7 2.77  39.58867
## 118 462239.5 6500271 58.6 19.7 2.40  39.58867
## 119 457980.5 6478448 62.6 19.0 2.78  39.58867
## 120 460337.2 6457270 59.2 17.8 3.00  39.58867
## 121 460415.0 6437318 48.8 14.9 2.70  39.58867
## 122 459339.5 6416020 50.3 15.3 2.10  39.58867
## 123 457447.1 6401523 54.8 16.8 3.40  39.58867
## 124 460815.3 6380176 39.9 15.2 4.80  39.58867
## 125 465851.6 6355547 40.0 12.6 2.30  39.58867
## 126 464229.4 6338212 37.2 13.4 2.10  39.58867
## 127 450953.0 6311663 31.4 17.7 1.74  39.58867
## 128 465263.7 6296646 40.4 14.9 1.97  39.58867
## 129 460321.8 6275948 22.8 13.0 1.78  39.58867
## 130 456056.2 6258558 23.7 11.5 1.46  39.58867
## 131 459850.7 6238129 36.8 10.9 1.74  39.58867
## 132 460984.6 6218295 26.6 13.2 2.40  39.58867
## 133 460561.6 6198268 27.7 14.5 1.80  39.58867
## 134 456152.1 6175430 28.4 14.5 1.53  39.58867
## 135 459156.5 6159880 32.4 15.9 1.71  39.58867
## 136 448405.0 6145931 46.8 26.7 1.90  39.58867
## 137 429559.3 6713097 35.3 20.9 1.40  39.58867
## 138 431144.2 6693667 56.2 27.3 1.60  39.58867
## 139 441061.9 6675047 61.5 22.8 2.40  39.58867
## 140 433488.8 6656236 64.8 24.7 2.30  39.58867
## 141 430584.4 6631845 59.9 23.5 2.20  39.58867
## 142 439114.4 6616771 63.7 23.2 2.10  39.58867
## 143 439227.2 6596823 58.9 22.5 3.10  39.58867
## 144 444384.3 6572176 58.0 23.0 2.48  39.58867
## 145 439454.5 6556926 60.1 23.2 2.45  39.58867
## 146 439488.0 6534813 61.5 21.9 2.30  39.58867
## 147 442482.7 6521239 59.7 19.8 2.28  39.58867
## 148 437738.5 6502293 58.5 20.7 2.40  39.58867
## 149 437197.4 6476251 53.4 18.8 2.34  39.58867
## 150 440689.2 6459394 53.4 18.1 2.01  39.58867
## 151 440150.9 6437219 47.4 26.7 1.70  39.58867
## 152 436267.8 6422024 52.5 20.6 1.90  39.58867
## 153 443077.9 6398613 45.9 18.9 3.20  39.58867
## 154 435863.8 6379223 38.4 13.1 1.90  39.58867
## 155 446603.0 6357883  0.0 12.6 1.67  39.58867
## 156 442929.0 6343522 26.5 12.1 1.75  39.58867
## 157 439491.9 6318077 12.8 10.0 1.33  39.58867
## 158 431151.7 6297512 20.0 14.9 1.95  39.58867
## 159 440484.8 6275979 19.8 10.8 1.47  39.58867
## 160 440098.6 6250709 30.1 12.1 1.45  39.58867
## 161 443317.3 6244373 12.3 12.5 1.64  39.58867
## 162 440967.5 6227407 29.3 16.2 1.50  39.58867
## 163 438685.1 6206640 34.9 19.0 1.60  39.58867
## 164 440748.3 6181170 24.4 15.7 1.60  39.58867
## 165 435022.6 6151497 20.9 13.8 1.60  39.58867
## 166 445299.8 6133188 28.7 17.9 1.70  39.58867
## 167 409646.2 6716651 33.7 19.3 1.40  39.58867
## 168 414484.4 6691598 26.9 13.2 1.58  39.58867
## 169 418050.8 6676478 43.9 22.1 1.30  39.58867
## 170 414909.6 6656061 58.0 21.9 2.20  39.58867
## 171 415617.6 6642029 56.1 20.6 2.00  39.58867
## 172 423666.9 6616209 58.0 25.9 2.50  39.58867
## 173 418240.5 6593812 54.5 23.7 1.90  39.58867
## 174 414895.0 6575416 61.9 22.4 2.28  39.58867
## 175 408415.6 6559531 58.1 26.5 2.30  39.58867
## 176 419639.8 6535327 62.4 21.1 2.00  39.58867
## 177 418820.7 6517895 57.7 19.5 2.50  39.58867
## 178 419416.8 6496936 53.1 21.7 2.50  39.58867
## 179 420262.1 6480316 59.2 19.8 2.10  39.58867
## 180 419729.1 6457032 55.6 15.4 1.70  39.58867
## 181 419886.4 6437079  0.0 10.2 0.80  39.58867
## 182 422555.7 6416999 46.6 20.2 1.50  39.58867
## 183 424187.6 6394253 36.1 17.8 2.02  39.58867
## 184 420123.2 6377094 35.1 19.1 1.70  39.58867
## 185 416997.7 6363302 19.9 10.0 1.42  39.58867
## 186 425171.0 6344753 22.0 13.9 2.40  39.58867
## 187 417917.2 6326746 38.5 22.6 2.91  39.58867
## 188 423547.6 6312202 19.8 12.7 1.54  39.58867
## 189 420675.5 6277073 26.3 13.1 1.87  39.58867
## 190 432630.4 6256211 20.8 13.3 1.72  39.58867
## 191 415059.8 6233151 28.7 17.1 1.70  39.58867
## 192 415498.8 6218453 18.4 12.2 1.70  39.58867
## 193 413075.1 6197490 15.5 12.4 1.50  39.58867
## 194 421888.2 6180592 18.2 13.9 1.50  39.58867
## 195 414970.2 6156712 14.8 12.2 1.60  39.58867
## 196 415114.3 6136351 24.6 15.1 2.20  39.58867
## 197 393546.6 6719911 15.9 19.3 1.00  39.58867
## 198 401410.3 6690743   NA   NA   NA  39.58867
## 199 400509.7 6673860 35.8 18.2 1.00  39.58867
## 200 388211.0 6657912 22.9  9.6 0.70  39.58867
## 201 397694.8 6636409 55.4 20.2 1.70  39.58867
## 202 401699.9 6616496 49.4 19.3 2.49  39.58867
## 203 398072.1 6596511 49.0 20.4 1.90  39.58867
## 204 398262.3 6576561 42.4 16.4 1.30  39.58867
## 205 391757.1 6558627 56.3 24.5 2.10  39.58867
## 206 399062.8 6541124 59.0 19.2 2.10  39.58867
## 207 402114.3 6516158 59.2 22.7 2.10  39.58867
## 208 399184.9 6498206 53.8 19.0 1.80  39.58867
## 209 393818.3 6473953 60.0 18.5 2.58  39.58867
## 210 390997.4 6456296 44.4 16.6 1.80  39.58867
## 211 399621.5 6436898 30.8 11.6 1.40  39.58867
## 212 398740.7 6419518 46.8 18.9 1.72  39.58867
## 213 406077.5 6399415 39.3 16.3 1.73  39.58867
## 214 401547.6 6373100  9.6 10.1 1.36  39.58867
## 215 401702.3 6355989 20.6 11.5 1.30  39.58867
## 216 406179.8 6343827 18.8 10.8 1.53  39.58867
## 217 407790.9 6317412 20.6 11.9 1.57  39.58867
## 218 409014.6 6295734 26.7 12.7 1.77  39.58867
## 219 401905.3 6279374 24.7 15.3 1.80  39.58867
## 220 401472.9 6255903 26.0 17.7 2.20  39.58867
## 221 398589.2 6235905 29.3 13.6 1.90  39.58867
## 222 402509.3 6212629 23.2 16.1 1.90  39.58867
## 223 393126.7 6195885 13.6 12.0 1.50  39.58867
## 224 400762.9 6181513 19.7 14.5 1.90  39.58867
## 225 394375.2 6156445 18.9 11.3 1.60  39.58867
## 226 400352.3 6138834 23.2 10.9 1.80  39.58867
## 227 375837.0 6714323 49.2 26.6 1.10  39.58867
## 228 381213.8 6709304 38.3 19.0 1.10  39.58867
## 229 365386.8 6695978 51.6 26.4 1.90  39.58867
## 230 388733.8 6667326   NA   NA   NA  39.58867
## 231 377040.0 6636195 35.0 19.6 1.80  39.58867
## 232 382613.1 6619021 49.3 19.7 1.80  39.58867
## 233 379647.2 6574478 20.7 16.9 1.30  39.58867
## 234 377952.0 6556394 20.5 15.1 0.60  39.58867
## 235 379858.9 6542664 53.1 23.0 2.18  39.58867
## 236 379912.8 6513835 60.7 25.1 2.50  39.58867
## 237 378648.6 6496538 67.4 26.8 2.50  39.58867
## 238 378883.2 6476585 54.9 23.1 2.10  39.58867
## 239 373300.2 6454149 59.8 20.8 1.70  39.58867
## 240 379356.0 6436677 53.6 26.5 2.00  39.58867
## 241 376539.5 6419165 15.8  6.3 0.50  39.58867
## 242 374614.2 6394682 36.1 15.9 1.50  39.58867
## 243 378122.0 6374189 23.1 11.0 1.60  39.58867
## 244 371612.3 6361513 40.0 18.9 2.30  39.58867
## 245 383588.6 6341233 41.7 23.9 2.90  39.58867
## 246 374332.4 6317590 31.9 18.7 2.30  39.58867
## 247 381633.0 6292313 26.4 10.0 2.00  39.58867
## 248 384814.0 6282948 15.2  8.7 1.60  39.58867
## 249 377971.7 6258673 11.5  8.9 1.80  39.58867
## 250 378353.9 6241497 18.8 10.2 1.70  39.58867
## 251 385668.5 6223915 15.6 10.1 1.30  39.58867
## 252 372920.8 6201697 10.7  9.7 1.50  39.58867
## 253 373822.7 6168505 10.6 12.7 2.40  39.58867
## 254 374283.5 6155857 17.6 11.4 2.00  39.58867
## 255 379627.0 6134719 58.2 15.2 2.20  39.58867
## 256 348711.8 6711924 15.4 15.6 0.90  39.58867
## 257 358202.9 6708195 31.1 13.7 1.40  39.58867
## 258 362072.5 6681197 29.0 17.2 0.90  39.58867
## 259 355738.7 6657258 27.9 13.6 1.40  39.58867
## 260 356043.7 6636299 29.0 19.9 1.00  39.58867
## 261 357028.1 6627659 41.5 22.8 1.70  39.58867
## 262 357836.5 6595032 26.6 27.8 1.09  39.58867
## 263 357181.3 6576089 19.1 20.0 0.70  39.58867
## 264 357460.4 6556071 20.1 16.1 0.40  39.58867
## 265 357799.4 6535105 15.5 15.3 0.50  39.58867
## 266 363571.9 6515526 50.8 21.7 2.00  39.58867
## 267 366450.7 6494150 32.8 17.6 1.10  39.58867
## 268 358491.9 6479635 48.7 21.5 1.40  39.58867
## 269 364859.8 6456431 48.0 16.9 1.70  39.58867
## 270 352374.6 6437236 47.2 22.2 1.70  39.58867
## 271 360020.4 6412716 32.2 14.3 2.20  39.58867
## 272 360639.9 6397543 42.5 14.2 1.40  39.58867
## 273 363104.2 6380446 46.1 13.5 1.40  39.58867
## 274 363949.4 6366384 36.6 13.2 1.50  39.58867
## 275 360297.2 6339369 36.3 20.8 2.40  39.58867
## 276 358906.9 6318191 22.9 12.8 2.40  39.58867
## 277 368023.8 6297300 31.9 15.2 3.00  39.58867
## 278 356796.3 6281601 24.7 15.1 1.60  39.58867
## 279 360840.7 6258420 26.6 16.1 1.80  39.58867
## 280 357728.1 6243261 11.6  8.2 1.10  39.58867
## 281 365059.0 6217702  4.0  5.5 1.20  39.58867
## 282 372915.4 6201693 12.4  7.2 1.50  39.58867
## 283 369232.8 6178825 10.5 10.2 1.90  39.58867
## 284 354127.0 6154878 15.4  8.4 2.00  39.58867
## 285 364634.4 6141008 10.6  7.7 2.20  39.58867
## 286 322034.1 6722199 44.0 27.3 1.90  39.58867
## 287 336988.4 6702457 33.9 13.2 1.60  39.58867
## 288 342934.9 6678617 21.0  8.4 1.10  39.58867
## 289 333942.3 6663125 39.0 20.5 1.85  39.58867
## 290 339487.4 6636141 30.0 17.8 1.40  39.58867
## 291 351274.0 6477363 58.2 34.0 1.90  39.58867
## 292 340122.0 6459510 52.3 26.7 0.80  39.58867
## 293 358358.8 6422919 48.1 14.2 2.10  39.58867
## 294 348091.4 6386836 47.9 13.1 1.90  39.58867
## 295 338135.2 6376681 43.4 20.9 1.70  39.58867
## 296 335929.7 6354151 49.1 30.6 2.50  39.58867
## 297 338757.8 6338937 28.2 18.3 2.00  39.58867
## 298 348477.5 6320510 14.6  9.3 1.50  39.58867
## 299 343471.4 6292974 30.3 14.9 1.50  39.58867
## 300 331109.7 6247386  8.8  7.5 1.10  39.58867
## 301 342413.3 6226849 11.2  8.6 1.40  39.58867
## 302 342963.0 6193915  9.9  7.1 1.50  39.58867
## 303 343616.1 6170952 13.7  5.0 1.50  39.58867
## 304 336324.5 6164347  0.0  6.6 1.70  39.58867
## 305 344720.9 6134254  0.0 12.1 2.10  39.58867
## 306 314936.8 6654862 26.7 10.3 1.10  39.58867
## 307 326153.8 6628397 28.4 14.4 1.30  39.58867
## 308 315026.9 6615022 18.0 10.2 1.29  39.58867
## 309 318722.8 6592813 22.9 12.7 1.00  39.58867
## 310 302508.5 6573027 57.8 27.8 3.30  39.58867
## 311 310568.5 6517139 40.4 22.0 0.80  39.58867
## 312 316152.5 6474608 46.1  9.6 1.80  39.58867
## 313 304247.8 6459885 28.3 13.2 2.40  39.58867
## 314 307888.3 6436238 36.9 15.0 0.80  39.58867
## 315 326290.2 6358537 52.1 24.2 1.50  39.58867
## 316 323251.7 6333011 17.7 11.7 0.60  39.58867
## 317 323107.8 6317898 13.4 11.7 1.60  39.58867
## 318 323918.5 6296467 13.4  9.0 1.20  39.58867
## 319 313421.1 6284488 12.8  9.6 1.70  39.58867
## 320 311319.3 6250934  9.2  6.0 1.30  39.58867
## 321 316141.0 6234887 17.5 10.9 1.40  39.58867
## 322 312199.4 6218220 12.2  8.5 1.70  39.58867
## 323 322774.6 6196569  7.7  5.3 1.30  39.58867
## 324 313315.5 6173792  7.1  6.8 1.40  39.58867
## 325 314626.1 6153624  5.1  6.9 1.20  39.58867
## 326 314547.3 6135107 23.5 12.2 1.50  39.58867
## 327 303239.8 6620640 21.5 14.4 1.40  39.58867
## 328 292241.2 6594051 29.3 16.0 2.00  39.58867
## 329 304823.8 6586070 38.9 15.7 1.21  39.58867
## 330 299754.1 6554098 41.7 15.3 0.86  39.58867
## 331 299158.8 6536651 33.4 17.3 1.10  39.58867
## 332 292274.0 6516662 14.2  6.9 1.03  39.58867
## 333 300315.6 6496947 56.8 22.6 1.10  39.58867
## 334 295007.2 6475754 47.8 19.3 1.20  39.58867
## 335 295427.5 6437040 28.8 14.4 1.50  39.58867
## 336 300698.5 6315618 11.1  8.4 1.10  39.58867
## 337 256689.0 6610529 39.0 12.5 1.10  39.58867
## 338 271612.2 6610072 33.9 14.2 1.10  39.58867
## 339 278760.3 6590394 31.3 16.4 1.50  39.58867
## 340 273995.8 6573165 25.9 11.3 0.60  39.58867
## 341 284724.4 6544882 55.3 21.1 0.60  39.58867
## 342 281465.5 6528077 18.7  9.1 0.60  39.58867
## 343 270532.2 6513493 29.3 14.1 1.00  39.58867
## 344 281067.8 6495186 28.0 10.0 1.10  39.58867
## 345 270093.9 6473571 46.2 17.1 2.10  39.58867
## 346 277578.3 6454923 29.7 10.5 0.80  39.58867
## 347 257921.1 6610371 33.0 14.3 1.60  39.58867
## 348 246082.7 6589469 38.5 17.1 1.50  39.58867
## 349 250409.8 6572978 30.6 10.2 1.20  39.58867
## 350 235888.3 6553601 40.2 14.0 1.30  39.58867
## 351 251686.1 6530851 26.3 11.5 0.90  39.58867
## 352 251673.6 6518741 23.8 10.5 0.80  39.58867
## 353 260311.3 6503994 31.3 16.1 1.40  39.58867
## 354 244261.6 6468475 33.2 17.0 2.70  39.58867
## 355 259768.2 6551776 15.0  7.3 1.30  39.58867

Manejo de bases de datos

library(dplyr)

muestreo |>
  mutate(mediaLimo = mean(Limo, na.rm = TRUE)) |> 
  filter(Limo > mediaLimo)
##           Xt      Yt Limo   CC    K mediaLimo
## 1   603163.6 6576899 67.0 29.3 2.30  39.58867
## 2   596537.1 6390518 66.0 28.9 2.02  39.58867
## 3   595665.5 6380484 62.9 27.5 1.38  39.58867
## 4   601138.5 6353446 57.4 25.4 1.60  39.58867
## 5   601798.1 6344096 61.1 25.3 1.36  39.58867
## 6   587501.2 6615272 65.3 25.4 2.40  39.58867
## 7   589808.2 6593001 62.6 25.7 2.30  39.58867
## 8   585406.5 6575712 69.3 23.4 1.81  39.58867
## 9   584319.9 6552571 64.6 25.1 3.00  39.58867
## 10  582795.8 6536823 59.0 33.5 2.33  39.58867
## 11  578393.8 6514830 68.5 29.3 2.24  39.58867
## 12  583401.3 6415459 73.7 21.8 2.30  39.58867
## 13  584191.3 6397971 59.8 25.9 1.99  39.58867
## 14  581920.4 6376827 61.0 24.7 1.78  39.58867
## 15  577542.6 6355542 61.8 23.6 1.93  39.58867
## 16  584591.7 6335074 56.7 28.0 1.70  39.58867
## 17  580626.0 6317237 44.8 25.4 2.10  39.58867
## 18  562987.4 6573479 63.1 25.0 2.00  39.58867
## 19  566036.4 6556137 61.5 25.3 2.30  39.58867
## 20  562334.3 6536965 61.1 24.0 2.38  39.58867
## 21  559369.8 6522722 64.4 25.1 2.24  39.58867
## 22  560282.0 6498671 56.3 22.6 1.43  39.58867
## 23  560549.5 6488513 55.4 25.8 2.17  39.58867
## 24  564983.2 6460704 67.8 25.2 2.30  39.58867
## 25  562125.9 6417162 65.6 27.3 2.31  39.58867
## 26  562506.2 6396998 64.6 28.2 2.14  39.58867
## 27  561288.0 6377057 59.5 22.6 2.07  39.58867
## 28  558959.4 6356407 53.2 25.9 1.92  39.58867
## 29  565136.4 6336920 52.3 24.4 2.05  39.58867
## 30  561075.5 6317870 55.1 26.6 1.83  39.58867
## 31  560453.6 6296711 45.4 18.6 1.60  39.58867
## 32  540132.5 6572395 60.2 29.8 1.80  39.58867
## 33  540066.3 6554923 47.9 19.0 1.70  39.58867
## 34  540779.8 6533415 63.8 22.8 2.50  39.58867
## 35  540148.3 6525651 62.4 22.9 2.00  39.58867
## 36  544374.1 6494569 66.2 28.5 2.43  39.58867
## 37  538352.2 6481364 53.0 23.5 2.10  39.58867
## 38  537104.6 6461968 64.5 26.5 2.58  39.58867
## 39  532245.0 6442189 89.1 30.0 3.02  39.58867
## 40  541745.0 6421084 51.8 20.9 1.73  39.58867
## 41  539590.4 6394002 47.3 17.9 1.86  39.58867
## 42  548155.4 6373990 54.0 20.1 1.96  39.58867
## 43  540549.2 6359775 52.1 20.4 2.02  39.58867
## 44  545162.9 6334934 51.7 20.7 1.94  39.58867
## 45  543884.1 6320334 44.1 18.7 3.30  39.58867
## 46  541060.1 6295328 41.4 19.2 1.72  39.58867
## 47  517735.0 6571859 61.3 21.9 2.80  39.58867
## 48  521452.9 6557077 54.7 20.0 1.88  39.58867
## 49  518981.7 6539152 56.4 27.7 1.90  39.58867
## 50  516398.8 6523475 62.2 21.4 2.30  39.58867
## 51  526721.8 6505980 64.3 22.6 2.20  39.58867
## 52  521566.0 6479408 51.6 18.7 1.70  39.58867
## 53  517747.8 6451336 64.5 25.2 2.30  39.58867
## 54  520817.7 6423081 63.6 27.7 3.30  39.58867
## 55  521616.1 6394127 58.0 23.8 2.30  39.58867
## 56  523663.2 6374580 54.3 20.9 2.50  39.58867
## 57  522161.5 6361886 54.5 18.8 2.30  39.58867
## 58  523948.5 6338317 46.8 17.6 2.40  39.58867
## 59  522520.0 6315974 43.7 17.6 2.10  39.58867
## 60  521364.1 6242214 43.3 21.4 1.80  39.58867
## 61  497504.3 6595468 69.9 20.9 2.60  39.58867
## 62  498859.5 6582924 48.7 28.4 2.30  39.58867
## 63  496547.8 6554849 61.2 22.3 2.70  39.58867
## 64  502725.1 6522890 43.8 18.4 2.10  39.58867
## 65  504966.4 6496754 61.7 20.7 2.20  39.58867
## 66  493626.2 6469272 60.6 23.3 2.70  39.58867
## 67  503024.7 6459416 88.1 18.7 2.40  39.58867
## 68  491398.7 6442386 61.8 21.8 2.20  39.58867
## 69  501034.0 6417872 63.0 20.0 2.40  39.58867
## 70  503837.2 6399237 57.3 33.0 2.60  39.58867
## 71  500936.9 6377536 55.9 21.8 2.20  39.58867
## 72  494748.6 6356124 49.6 17.7 2.20  39.58867
## 73  500781.0 6333918 44.5 20.0 2.00  39.58867
## 74  470472.3 6684993 57.8 24.3 2.20  39.58867
## 75  467093.8 6665904 47.0 17.9 2.80  39.58867
## 76  478336.1 6581409 55.4 25.7 3.20  39.58867
## 77  478088.6 6555574 59.8 20.8 2.16  39.58867
## 78  472449.7 6531218 62.7 20.3 2.11  39.58867
## 79  480565.5 6497231 60.9 19.9 2.30  39.58867
## 80  481351.8 6454471 51.6 25.7 1.75  39.58867
## 81  480685.6 6433792 61.5 21.4 2.70  39.58867
## 82  480716.9 6417424 55.2 21.6 2.70  39.58867
## 83  477386.8 6397107 52.0 21.3 2.40  39.58867
## 84  477023.6 6378135 57.6 17.5 2.60  39.58867
## 85  478417.9 6357823 51.4 15.7 2.40  39.58867
## 86  480871.4 6337608 42.9 13.7 2.20  39.58867
## 87  481955.4 6299139 43.8 17.2 1.80  39.58867
## 88  479213.4 6220087 41.7 17.5 1.60  39.58867
## 89  452453.0 6685685 59.2 24.3 2.80  39.58867
## 90  454630.4 6650994 57.4 23.2 2.00  39.58867
## 91  463017.2 6617131 53.0 25.3 2.40  39.58867
## 92  459804.0 6596920 39.9 13.5 1.74  39.58867
## 93  459951.2 6581356 44.3 19.6 2.10  39.58867
## 94  456426.2 6528027 58.4 21.7 2.77  39.58867
## 95  462239.5 6500271 58.6 19.7 2.40  39.58867
## 96  457980.5 6478448 62.6 19.0 2.78  39.58867
## 97  460337.2 6457270 59.2 17.8 3.00  39.58867
## 98  460415.0 6437318 48.8 14.9 2.70  39.58867
## 99  459339.5 6416020 50.3 15.3 2.10  39.58867
## 100 457447.1 6401523 54.8 16.8 3.40  39.58867
## 101 460815.3 6380176 39.9 15.2 4.80  39.58867
## 102 465851.6 6355547 40.0 12.6 2.30  39.58867
## 103 465263.7 6296646 40.4 14.9 1.97  39.58867
## 104 448405.0 6145931 46.8 26.7 1.90  39.58867
## 105 431144.2 6693667 56.2 27.3 1.60  39.58867
## 106 441061.9 6675047 61.5 22.8 2.40  39.58867
## 107 433488.8 6656236 64.8 24.7 2.30  39.58867
## 108 430584.4 6631845 59.9 23.5 2.20  39.58867
## 109 439114.4 6616771 63.7 23.2 2.10  39.58867
## 110 439227.2 6596823 58.9 22.5 3.10  39.58867
## 111 444384.3 6572176 58.0 23.0 2.48  39.58867
## 112 439454.5 6556926 60.1 23.2 2.45  39.58867
## 113 439488.0 6534813 61.5 21.9 2.30  39.58867
## 114 442482.7 6521239 59.7 19.8 2.28  39.58867
## 115 437738.5 6502293 58.5 20.7 2.40  39.58867
## 116 437197.4 6476251 53.4 18.8 2.34  39.58867
## 117 440689.2 6459394 53.4 18.1 2.01  39.58867
## 118 440150.9 6437219 47.4 26.7 1.70  39.58867
## 119 436267.8 6422024 52.5 20.6 1.90  39.58867
## 120 443077.9 6398613 45.9 18.9 3.20  39.58867
## 121 418050.8 6676478 43.9 22.1 1.30  39.58867
## 122 414909.6 6656061 58.0 21.9 2.20  39.58867
## 123 415617.6 6642029 56.1 20.6 2.00  39.58867
## 124 423666.9 6616209 58.0 25.9 2.50  39.58867
## 125 418240.5 6593812 54.5 23.7 1.90  39.58867
## 126 414895.0 6575416 61.9 22.4 2.28  39.58867
## 127 408415.6 6559531 58.1 26.5 2.30  39.58867
## 128 419639.8 6535327 62.4 21.1 2.00  39.58867
## 129 418820.7 6517895 57.7 19.5 2.50  39.58867
## 130 419416.8 6496936 53.1 21.7 2.50  39.58867
## 131 420262.1 6480316 59.2 19.8 2.10  39.58867
## 132 419729.1 6457032 55.6 15.4 1.70  39.58867
## 133 422555.7 6416999 46.6 20.2 1.50  39.58867
## 134 397694.8 6636409 55.4 20.2 1.70  39.58867
## 135 401699.9 6616496 49.4 19.3 2.49  39.58867
## 136 398072.1 6596511 49.0 20.4 1.90  39.58867
## 137 398262.3 6576561 42.4 16.4 1.30  39.58867
## 138 391757.1 6558627 56.3 24.5 2.10  39.58867
## 139 399062.8 6541124 59.0 19.2 2.10  39.58867
## 140 402114.3 6516158 59.2 22.7 2.10  39.58867
## 141 399184.9 6498206 53.8 19.0 1.80  39.58867
## 142 393818.3 6473953 60.0 18.5 2.58  39.58867
## 143 390997.4 6456296 44.4 16.6 1.80  39.58867
## 144 398740.7 6419518 46.8 18.9 1.72  39.58867
## 145 375837.0 6714323 49.2 26.6 1.10  39.58867
## 146 365386.8 6695978 51.6 26.4 1.90  39.58867
## 147 382613.1 6619021 49.3 19.7 1.80  39.58867
## 148 379858.9 6542664 53.1 23.0 2.18  39.58867
## 149 379912.8 6513835 60.7 25.1 2.50  39.58867
## 150 378648.6 6496538 67.4 26.8 2.50  39.58867
## 151 378883.2 6476585 54.9 23.1 2.10  39.58867
## 152 373300.2 6454149 59.8 20.8 1.70  39.58867
## 153 379356.0 6436677 53.6 26.5 2.00  39.58867
## 154 371612.3 6361513 40.0 18.9 2.30  39.58867
## 155 383588.6 6341233 41.7 23.9 2.90  39.58867
## 156 379627.0 6134719 58.2 15.2 2.20  39.58867
## 157 357028.1 6627659 41.5 22.8 1.70  39.58867
## 158 363571.9 6515526 50.8 21.7 2.00  39.58867
## 159 358491.9 6479635 48.7 21.5 1.40  39.58867
## 160 364859.8 6456431 48.0 16.9 1.70  39.58867
## 161 352374.6 6437236 47.2 22.2 1.70  39.58867
## 162 360639.9 6397543 42.5 14.2 1.40  39.58867
## 163 363104.2 6380446 46.1 13.5 1.40  39.58867
## 164 322034.1 6722199 44.0 27.3 1.90  39.58867
## 165 351274.0 6477363 58.2 34.0 1.90  39.58867
## 166 340122.0 6459510 52.3 26.7 0.80  39.58867
## 167 358358.8 6422919 48.1 14.2 2.10  39.58867
## 168 348091.4 6386836 47.9 13.1 1.90  39.58867
## 169 338135.2 6376681 43.4 20.9 1.70  39.58867
## 170 335929.7 6354151 49.1 30.6 2.50  39.58867
## 171 302508.5 6573027 57.8 27.8 3.30  39.58867
## 172 310568.5 6517139 40.4 22.0 0.80  39.58867
## 173 316152.5 6474608 46.1  9.6 1.80  39.58867
## 174 326290.2 6358537 52.1 24.2 1.50  39.58867
## 175 299754.1 6554098 41.7 15.3 0.86  39.58867
## 176 300315.6 6496947 56.8 22.6 1.10  39.58867
## 177 295007.2 6475754 47.8 19.3 1.20  39.58867
## 178 284724.4 6544882 55.3 21.1 0.60  39.58867
## 179 270093.9 6473571 46.2 17.1 2.10  39.58867
## 180 235888.3 6553601 40.2 14.0 1.30  39.58867

Manejo de bases de datos

library(dplyr)

muestreo |>
  mutate(mediaLimo = mean(Limo, na.rm = TRUE)) |> 
  filter(Limo > mediaLimo) |> 
  select(-mediaLimo)
##           Xt      Yt Limo   CC    K
## 1   603163.6 6576899 67.0 29.3 2.30
## 2   596537.1 6390518 66.0 28.9 2.02
## 3   595665.5 6380484 62.9 27.5 1.38
## 4   601138.5 6353446 57.4 25.4 1.60
## 5   601798.1 6344096 61.1 25.3 1.36
## 6   587501.2 6615272 65.3 25.4 2.40
## 7   589808.2 6593001 62.6 25.7 2.30
## 8   585406.5 6575712 69.3 23.4 1.81
## 9   584319.9 6552571 64.6 25.1 3.00
## 10  582795.8 6536823 59.0 33.5 2.33
## 11  578393.8 6514830 68.5 29.3 2.24
## 12  583401.3 6415459 73.7 21.8 2.30
## 13  584191.3 6397971 59.8 25.9 1.99
## 14  581920.4 6376827 61.0 24.7 1.78
## 15  577542.6 6355542 61.8 23.6 1.93
## 16  584591.7 6335074 56.7 28.0 1.70
## 17  580626.0 6317237 44.8 25.4 2.10
## 18  562987.4 6573479 63.1 25.0 2.00
## 19  566036.4 6556137 61.5 25.3 2.30
## 20  562334.3 6536965 61.1 24.0 2.38
## 21  559369.8 6522722 64.4 25.1 2.24
## 22  560282.0 6498671 56.3 22.6 1.43
## 23  560549.5 6488513 55.4 25.8 2.17
## 24  564983.2 6460704 67.8 25.2 2.30
## 25  562125.9 6417162 65.6 27.3 2.31
## 26  562506.2 6396998 64.6 28.2 2.14
## 27  561288.0 6377057 59.5 22.6 2.07
## 28  558959.4 6356407 53.2 25.9 1.92
## 29  565136.4 6336920 52.3 24.4 2.05
## 30  561075.5 6317870 55.1 26.6 1.83
## 31  560453.6 6296711 45.4 18.6 1.60
## 32  540132.5 6572395 60.2 29.8 1.80
## 33  540066.3 6554923 47.9 19.0 1.70
## 34  540779.8 6533415 63.8 22.8 2.50
## 35  540148.3 6525651 62.4 22.9 2.00
## 36  544374.1 6494569 66.2 28.5 2.43
## 37  538352.2 6481364 53.0 23.5 2.10
## 38  537104.6 6461968 64.5 26.5 2.58
## 39  532245.0 6442189 89.1 30.0 3.02
## 40  541745.0 6421084 51.8 20.9 1.73
## 41  539590.4 6394002 47.3 17.9 1.86
## 42  548155.4 6373990 54.0 20.1 1.96
## 43  540549.2 6359775 52.1 20.4 2.02
## 44  545162.9 6334934 51.7 20.7 1.94
## 45  543884.1 6320334 44.1 18.7 3.30
## 46  541060.1 6295328 41.4 19.2 1.72
## 47  517735.0 6571859 61.3 21.9 2.80
## 48  521452.9 6557077 54.7 20.0 1.88
## 49  518981.7 6539152 56.4 27.7 1.90
## 50  516398.8 6523475 62.2 21.4 2.30
## 51  526721.8 6505980 64.3 22.6 2.20
## 52  521566.0 6479408 51.6 18.7 1.70
## 53  517747.8 6451336 64.5 25.2 2.30
## 54  520817.7 6423081 63.6 27.7 3.30
## 55  521616.1 6394127 58.0 23.8 2.30
## 56  523663.2 6374580 54.3 20.9 2.50
## 57  522161.5 6361886 54.5 18.8 2.30
## 58  523948.5 6338317 46.8 17.6 2.40
## 59  522520.0 6315974 43.7 17.6 2.10
## 60  521364.1 6242214 43.3 21.4 1.80
## 61  497504.3 6595468 69.9 20.9 2.60
## 62  498859.5 6582924 48.7 28.4 2.30
## 63  496547.8 6554849 61.2 22.3 2.70
## 64  502725.1 6522890 43.8 18.4 2.10
## 65  504966.4 6496754 61.7 20.7 2.20
## 66  493626.2 6469272 60.6 23.3 2.70
## 67  503024.7 6459416 88.1 18.7 2.40
## 68  491398.7 6442386 61.8 21.8 2.20
## 69  501034.0 6417872 63.0 20.0 2.40
## 70  503837.2 6399237 57.3 33.0 2.60
## 71  500936.9 6377536 55.9 21.8 2.20
## 72  494748.6 6356124 49.6 17.7 2.20
## 73  500781.0 6333918 44.5 20.0 2.00
## 74  470472.3 6684993 57.8 24.3 2.20
## 75  467093.8 6665904 47.0 17.9 2.80
## 76  478336.1 6581409 55.4 25.7 3.20
## 77  478088.6 6555574 59.8 20.8 2.16
## 78  472449.7 6531218 62.7 20.3 2.11
## 79  480565.5 6497231 60.9 19.9 2.30
## 80  481351.8 6454471 51.6 25.7 1.75
## 81  480685.6 6433792 61.5 21.4 2.70
## 82  480716.9 6417424 55.2 21.6 2.70
## 83  477386.8 6397107 52.0 21.3 2.40
## 84  477023.6 6378135 57.6 17.5 2.60
## 85  478417.9 6357823 51.4 15.7 2.40
## 86  480871.4 6337608 42.9 13.7 2.20
## 87  481955.4 6299139 43.8 17.2 1.80
## 88  479213.4 6220087 41.7 17.5 1.60
## 89  452453.0 6685685 59.2 24.3 2.80
## 90  454630.4 6650994 57.4 23.2 2.00
## 91  463017.2 6617131 53.0 25.3 2.40
## 92  459804.0 6596920 39.9 13.5 1.74
## 93  459951.2 6581356 44.3 19.6 2.10
## 94  456426.2 6528027 58.4 21.7 2.77
## 95  462239.5 6500271 58.6 19.7 2.40
## 96  457980.5 6478448 62.6 19.0 2.78
## 97  460337.2 6457270 59.2 17.8 3.00
## 98  460415.0 6437318 48.8 14.9 2.70
## 99  459339.5 6416020 50.3 15.3 2.10
## 100 457447.1 6401523 54.8 16.8 3.40
## 101 460815.3 6380176 39.9 15.2 4.80
## 102 465851.6 6355547 40.0 12.6 2.30
## 103 465263.7 6296646 40.4 14.9 1.97
## 104 448405.0 6145931 46.8 26.7 1.90
## 105 431144.2 6693667 56.2 27.3 1.60
## 106 441061.9 6675047 61.5 22.8 2.40
## 107 433488.8 6656236 64.8 24.7 2.30
## 108 430584.4 6631845 59.9 23.5 2.20
## 109 439114.4 6616771 63.7 23.2 2.10
## 110 439227.2 6596823 58.9 22.5 3.10
## 111 444384.3 6572176 58.0 23.0 2.48
## 112 439454.5 6556926 60.1 23.2 2.45
## 113 439488.0 6534813 61.5 21.9 2.30
## 114 442482.7 6521239 59.7 19.8 2.28
## 115 437738.5 6502293 58.5 20.7 2.40
## 116 437197.4 6476251 53.4 18.8 2.34
## 117 440689.2 6459394 53.4 18.1 2.01
## 118 440150.9 6437219 47.4 26.7 1.70
## 119 436267.8 6422024 52.5 20.6 1.90
## 120 443077.9 6398613 45.9 18.9 3.20
## 121 418050.8 6676478 43.9 22.1 1.30
## 122 414909.6 6656061 58.0 21.9 2.20
## 123 415617.6 6642029 56.1 20.6 2.00
## 124 423666.9 6616209 58.0 25.9 2.50
## 125 418240.5 6593812 54.5 23.7 1.90
## 126 414895.0 6575416 61.9 22.4 2.28
## 127 408415.6 6559531 58.1 26.5 2.30
## 128 419639.8 6535327 62.4 21.1 2.00
## 129 418820.7 6517895 57.7 19.5 2.50
## 130 419416.8 6496936 53.1 21.7 2.50
## 131 420262.1 6480316 59.2 19.8 2.10
## 132 419729.1 6457032 55.6 15.4 1.70
## 133 422555.7 6416999 46.6 20.2 1.50
## 134 397694.8 6636409 55.4 20.2 1.70
## 135 401699.9 6616496 49.4 19.3 2.49
## 136 398072.1 6596511 49.0 20.4 1.90
## 137 398262.3 6576561 42.4 16.4 1.30
## 138 391757.1 6558627 56.3 24.5 2.10
## 139 399062.8 6541124 59.0 19.2 2.10
## 140 402114.3 6516158 59.2 22.7 2.10
## 141 399184.9 6498206 53.8 19.0 1.80
## 142 393818.3 6473953 60.0 18.5 2.58
## 143 390997.4 6456296 44.4 16.6 1.80
## 144 398740.7 6419518 46.8 18.9 1.72
## 145 375837.0 6714323 49.2 26.6 1.10
## 146 365386.8 6695978 51.6 26.4 1.90
## 147 382613.1 6619021 49.3 19.7 1.80
## 148 379858.9 6542664 53.1 23.0 2.18
## 149 379912.8 6513835 60.7 25.1 2.50
## 150 378648.6 6496538 67.4 26.8 2.50
## 151 378883.2 6476585 54.9 23.1 2.10
## 152 373300.2 6454149 59.8 20.8 1.70
## 153 379356.0 6436677 53.6 26.5 2.00
## 154 371612.3 6361513 40.0 18.9 2.30
## 155 383588.6 6341233 41.7 23.9 2.90
## 156 379627.0 6134719 58.2 15.2 2.20
## 157 357028.1 6627659 41.5 22.8 1.70
## 158 363571.9 6515526 50.8 21.7 2.00
## 159 358491.9 6479635 48.7 21.5 1.40
## 160 364859.8 6456431 48.0 16.9 1.70
## 161 352374.6 6437236 47.2 22.2 1.70
## 162 360639.9 6397543 42.5 14.2 1.40
## 163 363104.2 6380446 46.1 13.5 1.40
## 164 322034.1 6722199 44.0 27.3 1.90
## 165 351274.0 6477363 58.2 34.0 1.90
## 166 340122.0 6459510 52.3 26.7 0.80
## 167 358358.8 6422919 48.1 14.2 2.10
## 168 348091.4 6386836 47.9 13.1 1.90
## 169 338135.2 6376681 43.4 20.9 1.70
## 170 335929.7 6354151 49.1 30.6 2.50
## 171 302508.5 6573027 57.8 27.8 3.30
## 172 310568.5 6517139 40.4 22.0 0.80
## 173 316152.5 6474608 46.1  9.6 1.80
## 174 326290.2 6358537 52.1 24.2 1.50
## 175 299754.1 6554098 41.7 15.3 0.86
## 176 300315.6 6496947 56.8 22.6 1.10
## 177 295007.2 6475754 47.8 19.3 1.20
## 178 284724.4 6544882 55.3 21.1 0.60
## 179 270093.9 6473571 46.2 17.1 2.10
## 180 235888.3 6553601 40.2 14.0 1.30

Manejo de bases de datos

library(dplyr)

base_subset <- 
  muestreo |>
  mutate(mediaLimo = mean(Limo, na.rm = TRUE)) |> 
  filter(Limo > mediaLimo) |> 
  select(-mediaLimo)

Conversión de data.frame a objeto espacial

print(muestreo <- st_as_sf(muestreo, 
                           coords = c("Xt", "Yt"), 
                           crs = 32720), 
      n = 5)
## Simple feature collection with 355 features and 3 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 235888.3 ymin: 6133188 xmax: 603163.6 ymax: 6722199
## Projected CRS: WGS 84 / UTM zone 20S
## First 5 features:
##   Limo   CC    K                 geometry
## 1 67.0 29.3 2.30 POINT (603163.6 6576899)
## 2 66.0 28.9 2.02 POINT (596537.1 6390518)
## 3 62.9 27.5 1.38 POINT (595665.5 6380484)
## 4 57.4 25.4 1.60 POINT (601138.5 6353446)
## 5 61.1 25.3 1.36 POINT (601798.1 6344096)
summary(muestreo)
##       Limo             CC              K                  geometry  
##  Min.   : 0.00   Min.   : 5.00   Min.   :0.400   POINT        :355  
##  1st Qu.:24.60   1st Qu.:13.10   1st Qu.:1.500   epsg:32720   :  0  
##  Median :40.00   Median :17.70   Median :1.810   +proj=utm ...:  0  
##  Mean   :39.59   Mean   :17.72   Mean   :1.856                      
##  3rd Qu.:55.90   3rd Qu.:21.90   3rd Qu.:2.240                      
##  Max.   :89.10   Max.   :34.00   Max.   :4.800                      
##  NA's   :2       NA's   :2       NA's   :2
plot(muestreo, pch = 18 , cex = 3)

ggplot(muestreo) +
  geom_sf()

ggplot(muestreo) +
  geom_sf(aes(fill = Limo), shape = 22, size = 3)

Lectura de archivo Shapefile

Shapefile consisten en varios archivos de datos espaciales, con el mimso nombre base que residen en el mismo directorio. Fue desarrollado por la compañía ESRI.

Los archivos obligatorios son:

  • .shp: es el archivo principal que almacena la geometría de la entidad
  • .shx: es el archivo de índice que almacena el índice de la geometría de la entidad
  • .dbf: es la tabla dBASE que almacena la información de atributos de las entidades

Pero pueden tener otros tipos de archivos

.prj, .xml, .sbn, .sbx ….

Lectura de archivo GeoPackage

  • Es un formato de archivo universal construido sobre la base de SQLite, para compartir y transferir datos espaciales vectoriales y raster.
  • A diferencia de los shapesfiles, se trata de un único archivo .gpkg, por lo que es ideal para transferir información geoespacial
  • Diseñado para almacenar datos complejos y voluminosos (hasta 140 TB)
  • Permite almacenar diferentes tipos de geometrías en un mismo archivo
  • Destaca por su flexibilidad pudiendolo utilizar de muchas maneras, por lo que puede reemplazar al formato shapefile

Vectoriales

print(departamentos <- read_sf("datos/deptos_cba", stringsAsFactors = TRUE), n = 3)
## Simple feature collection with 26 features and 5 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -65.77198 ymin: -35.00013 xmax: -61.77089 ymax: -29.50042
## Geodetic CRS:  WGS 84
## # A tibble: 26 × 6
##   objectid departa            cabecer provincia fuente                  geometry
##      <dbl> <fct>              <fct>   <fct>     <fct>              <POLYGON [°]>
## 1      393 PRESIDENTE ROQUE … LABOUL… CORDOBA   CATAS… ((-62.8198 -33.89651, -6…
## 2      341 TERCERO ARRIBA     OLIVA   CORDOBA   CATAS… ((-63.11768 -32.00111, -…
## 3      342 JUAREZ CELMAN      LA CAR… CORDOBA   CATAS… ((-63.55538 -32.83089, -…
## # ℹ 23 more rows

Vectoriales

print(departamentos <- read_sf("datos/deptos_cba", stringsAsFactors = TRUE), n = 3)
## Simple feature collection with 26 features and 5 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -65.77198 ymin: -35.00013 xmax: -61.77089 ymax: -29.50042
## Geodetic CRS:  WGS 84
## # A tibble: 26 × 6
##   objectid departa            cabecer provincia fuente                  geometry
##      <dbl> <fct>              <fct>   <fct>     <fct>              <POLYGON [°]>
## 1      393 PRESIDENTE ROQUE … LABOUL… CORDOBA   CATAS… ((-62.8198 -33.89651, -6…
## 2      341 TERCERO ARRIBA     OLIVA   CORDOBA   CATAS… ((-63.11768 -32.00111, -…
## 3      342 JUAREZ CELMAN      LA CAR… CORDOBA   CATAS… ((-63.55538 -32.83089, -…
## # ℹ 23 more rows
summary(departamentos)
##     objectid                   departa           cabecer     provincia 
##  Min.   :322.0   CALAMUCHITA       : 1   ALTA GRACIA : 1   CORDOBA:26  
##  1st Qu.:328.2   CAPITAL           : 1   BEL VILLE   : 1               
##  Median :334.5   COLON             : 1   CORDOBA     : 1               
##  Mean   :342.9   CRUZ DEL EJE      : 1   COSQUIN     : 1               
##  3rd Qu.:340.8   GENERAL ROCA      : 1   CRUZ DEL EJE: 1               
##  Max.   :433.0   GENERAL SAN MARTIN: 1   DEAN FUNES  : 1               
##                  (Other)           :20   (Other)     :20               
##               fuente            geometry 
##  CATASTRO CORDOBA:26   POLYGON      :26  
##                        epsg:4326    : 0  
##                        +proj=long...: 0  
##                                          
##                                          
##                                          
## 
plot(departamentos)

Ahora visualicemos cuencas

print(cuencas <- read_sf("datos/cuencas_cba/cuencas_cba.gpkg", stringsAsFactors = TRUE), n = 2)
## Simple feature collection with 32 features and 6 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 3520724 ymin: 6124258 xmax: 3898029 ymax: 6736392
## Projected CRS: unnamed
## # A tibble: 32 × 7
##         AREA PERIMETER COR3_ COR3_ID CUENCA    SISTEMA                      geom
##        <dbl>     <dbl> <dbl>   <dbl> <fct>     <fct>               <POLYGON [m]>
## 1 2939859000   337780.     2      28 SISTEMA … SISTEM… ((3622555 6732250, 36239…
## 2  382742500    95968.     3      30 CUENCA D… SISTEM… ((3633386 6733595, 36335…
## # ℹ 30 more rows
summary(cuencas, maxsum = 3)
##       AREA             PERIMETER           COR3_          COR3_ID     
##  Min.   :9.626e+07   Min.   :  45776   Min.   : 2.00   Min.   : 1.00  
##  1st Qu.:1.514e+09   1st Qu.: 326552   1st Qu.: 9.75   1st Qu.: 8.75  
##  Median :2.829e+09   Median : 427580   Median :17.50   Median :16.50  
##  Mean   :5.134e+09   Mean   : 492282   Mean   :17.69   Mean   :16.50  
##  3rd Qu.:5.330e+09   3rd Qu.: 580937   3rd Qu.:25.25   3rd Qu.:24.25  
##  Max.   :5.365e+10   Max.   :1666874   Max.   :34.00   Max.   :32.00  
##                                  CUENCA                      SISTEMA  
##  CUENCA DE LAS SALINAS GRANDES      : 2   SISTEMA MORTEROS       :12  
##  CUENCA DE LA LAGUNA DE MAR CHIQUITA: 1   SISTEMA SALINAS GRANDES:11  
##  (Other)                            :29   (Other)                : 9  
##                                                                       
##                                                                       
##                                                                       
##             geom   
##  POLYGON      :32  
##  epsg:NA      : 0  
##  +proj=tmer...: 0  
##                    
##                    
## 
plot(cuencas)

Sistema de coordenadas de referencia

st_crs(departamentos)
## Coordinate Reference System:
##   User input: WGS 84 
##   wkt:
## GEOGCRS["WGS 84",
##     DATUM["World Geodetic System 1984",
##         ELLIPSOID["WGS 84",6378137,298.257223563,
##             LENGTHUNIT["metre",1]]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["latitude",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["longitude",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     ID["EPSG",4326]]
st_crs(cuencas)
## Coordinate Reference System:
##   User input: unnamed 
##   wkt:
## PROJCRS["unnamed",
##     BASEGEOGCRS["WGS 84",
##         DATUM["World Geodetic System 1984",
##             ELLIPSOID["WGS 84",6378137,298.257223563,
##                 LENGTHUNIT["metre",1]]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4326]],
##     CONVERSION["unnamed",
##         METHOD["Transverse Mercator",
##             ID["EPSG",9807]],
##         PARAMETER["Latitude of natural origin",-90,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",-66,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["Scale factor at natural origin",1,
##             SCALEUNIT["unity",1],
##             ID["EPSG",8805]],
##         PARAMETER["False easting",3500000,
##             LENGTHUNIT["Meter",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",0,
##             LENGTHUNIT["Meter",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["(E)",east,
##             ORDER[1],
##             LENGTHUNIT["Meter",1]],
##         AXIS["(N)",north,
##             ORDER[2],
##             LENGTHUNIT["Meter",1]]]
st_crs(departamentos) == st_crs(cuencas)
## [1] FALSE
cuencas <- st_transform(cuencas, st_crs(departamentos))
st_crs(cuencas)
## Coordinate Reference System:
##   User input: WGS 84 
##   wkt:
## GEOGCRS["WGS 84",
##     DATUM["World Geodetic System 1984",
##         ELLIPSOID["WGS 84",6378137,298.257223563,
##             LENGTHUNIT["metre",1]]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["latitude",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["longitude",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     ID["EPSG",4326]]
st_crs(departamentos) == st_crs(cuencas)
## [1] TRUE
print(cuencas, n = 4)
## Simple feature collection with 32 features and 6 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -65.78294 ymin: -35.00037 xmax: -61.77663 ymax: -29.49721
## Geodetic CRS:  WGS 84
## # A tibble: 32 × 7
##         AREA PERIMETER COR3_ COR3_ID CUENCA    SISTEMA                      geom
## *      <dbl>     <dbl> <dbl>   <dbl> <fct>     <fct>               <POLYGON [°]>
## 1 2939859000   337780.     2      28 SISTEMA … SISTEM… ((-64.73567 -29.53934, -…
## 2  382742500    95968.     3      30 CUENCA D… SISTEM… ((-64.62412 -29.5261, -6…
## 3 2702037000   454788.     4      27 CUENCA D… SISTEM… ((-64.83056 -29.55093, -…
## 4 2717994000   391502.     5      31 CUENCA D… SISTEM… ((-64.83056 -29.55093, -…
## # ℹ 28 more rows

ggplot(muestreo) +
  geom_sf(aes(fill = Limo), shape = 22, size = 3) +
  geom_sf(data = departamentos)
ggplot(muestreo) +
  geom_sf(data = departamentos) +
  geom_sf(aes(fill = Limo), shape = 22, size = 3) 

Visualización de datos

ggplot() +
  geom_sf(data = cuencas)

Visualización de datos

ggplot() +
  geom_sf(data = cuencas) +
  geom_sf(data = muestreo)

Visualización de datos

ggplot() +
  geom_sf(data = cuencas) +
  geom_sf(data = muestreo, aes(color = Limo), size = 3)

Visualización de datos

ggplot() +
  geom_sf(data = cuencas) +
  geom_sf(data = muestreo, aes(color = Limo), size = 3) +
  scale_color_continuous(type = "viridis")

Visualización de datos


ggplot() +
  geom_sf(data = cuencas) +
  geom_sf(data = muestreo, aes(color = Limo), size = 3) +
  scale_color_continuous(type = "viridis", na.value = "pink")

Cuantos puntos de muestreo hay en cada cuenca???

muestreoLatLong <- st_transform(muestreo, st_crs(departamentos))
st_covers(cuencas, muestreoLatLong)
## Sparse geometry binary predicate list of length 32, where the predicate
## was `covers'
## first 10 elements:
##  1: 197, 227, 228, 229, 257, 258
##  2: 256
##  3: 231, 259, 286, 287, 288
##  4: (empty)
##  5: 167
##  6: 110, 137
##  7: 111, 138, 139, 140, 168, 169, 170, 198, 199, 200, ...
##  8: 88, 89
##  9: 260, 261, 289, 290, 306, 307
##  10: 308
cuencasUTM <- st_transform(cuencas, st_crs(muestreo))
lengths(st_covers(cuencasUTM, muestreo))
##  [1]   6   1   5   0   1   2  11   2   6   1   0   4   5   5   6   4   1   6   8
## [20]   8   0  18  14  34   2 129   4  13  14   9  16  17
st_area(cuencas)
lengths(st_covers(cuencasUTM, muestreo))/st_area(cuencasUTM)
## Units: [m^2]
##  [1]  2941319396   383007897  2703593448  2720410977   233947031  1187897765
##  [7]  4147041584  4319989815  1848644910  1582180011  5114949009  1716889844
## [13]  1788223705  1313473401  3243021263  2523356652  1167268758  2279175622
## [19]  3007043779  3785467430    96348171  7828698301  6982510695 15789485675
## [25]   705525016 53588902736  1121037767  5951933553  6389315550  3648665788
## [31]  6685136916  7414242043
## Units: [1/m^2]
##  [1] 2.043139e-09 2.614800e-09 1.851958e-09 0.000000e+00 4.282275e-09
##  [6] 1.686827e-09 2.657137e-09 4.638433e-10 3.249556e-09 6.326527e-10
## [11] 0.000000e+00 2.333735e-09 2.800420e-09 3.808526e-09 1.851379e-09
## [16] 1.586875e-09 8.574153e-10 2.636741e-09 2.664597e-09 2.116604e-09
## [21] 0.000000e+00 2.302539e-09 2.005620e-09 2.156470e-09 2.838991e-09
## [26] 2.410084e-09 3.569966e-09 2.185862e-09 2.192333e-09 2.469177e-09
## [31] 2.395066e-09 2.293799e-09
puntosKm <- lengths(st_covers(cuencasUTM, muestreo))/units::set_units(st_area(cuencasUTM), km^2)
cuencasUTM$CantidadMuestrasKm <- as.numeric(puntosKm)
cuencasUTM$CantidadMuestrasKm
##  [1] 0.0020431392 0.0026148004 0.0018519580 0.0000000000 0.0042822751
##  [6] 0.0016868273 0.0026571370 0.0004638433 0.0032495556 0.0006326527
## [11] 0.0000000000 0.0023337350 0.0028004203 0.0038085260 0.0018513786
## [16] 0.0015868747 0.0008574153 0.0026367409 0.0026645968 0.0021166040
## [21] 0.0000000000 0.0023025389 0.0020056198 0.0021564699 0.0028389907
## [26] 0.0024100838 0.0035699660 0.0021858622 0.0021923332 0.0024691772
## [31] 0.0023950658 0.0022937989

ggplot(cuencasUTM) +
  geom_sf(aes(fill = CantidadMuestrasKm))
st_covers(cuencasUTM,muestreo)
## Sparse geometry binary predicate list of length 32, where the predicate
## was `covers'
## first 10 elements:
##  1: 197, 227, 228, 229, 257, 258
##  2: 256
##  3: 231, 259, 286, 287, 288
##  4: (empty)
##  5: 167
##  6: 110, 137
##  7: 111, 138, 139, 140, 168, 169, 170, 198, 199, 200, ...
##  8: 88, 89
##  9: 260, 261, 289, 290, 306, 307
##  10: 308
 mediaLimo <- sapply(st_covers(cuencasUTM,muestreo), function(x) {
  mean(muestreo[x,][["Limo"]], na.rm = TRUE)
     })
mediaLimo

##  [1] 35.85000 15.40000 32.36000      NaN 33.70000 47.25000 47.48889 52.40000
##  [9] 32.43333 18.00000      NaN 50.67500 65.76000 35.88000 37.73333 22.52500
## [17] 29.30000 55.38333 46.33750 51.63750      NaN 52.18889 33.80714 55.46176
## [25] 63.75000 42.23566 30.92500 25.74615 17.64286 32.40000 20.01250 15.09412

Visualizacion

cuencasUTM$MediaLimo <- mediaLimo
ggplot(cuencasUTM) +
  geom_sf(aes(fill = MediaLimo))

Visualización de datos

ggplot(cuencasUTM) +
  geom_sf(aes(fill = MediaLimo)) +
  labs(fill = "Limo (%)")

Visualización de datos

ggplot(cuencasUTM) +
  geom_sf(aes(fill = MediaLimo)) +
  labs(fill = "Limo (%)") + 
  ggspatial::annotation_north_arrow(
    location = "tr", 
    which_north = "grid"
    )

Paquete tmap

  • La sintaxis es similar a ggplot2, pero orientada a mapas
  • La mayoría de las funciones comienzan con tm_
  • Para comenzar a graficar, es necesario especificarlo con tm_shape
  • Las capas se agregan mediante +
  • Permite graficar mapas estáticos o interactivos con el mismo código tmap_mode().
tm_shape(cuencasUTM) +
  tm_fill()

tm_shape(cuencasUTM) +
  tm_fill("MediaLimo")

tm_shape(cuencasUTM) +
  tm_fill("MediaLimo") +
  tm_borders()

tm_shape(cuencasUTM) +
  tm_fill("MediaLimo", style = "quantile") +
  tm_borders() 

tm_shape(cuencasUTM) +
  tm_fill("MediaLimo", style = "cont") +
  tm_borders() 

tmap_mode("view")
tm_shape(cuencasUTM) +
  tm_fill("MediaLimo", style = "cont") +
  tm_borders() +
  tm_basemap("Esri.WorldTopoMap")
tmap_mode("view")
tm_shape(cuencasUTM) +
  tm_fill("MediaLimo",
          fill.scale = tm_scale_intervals(style = 'quantile'),
          fill_alpha = 0.8) +
  tm_borders() +
  tm_basemap(c("Stadia.Stamen.Watercolor",
               "Esri",
               "OpenTopoMap",
               "Stamen.Terrain"))
# names(leaflet::providers)
tmap_mode("plot")
cuencas_tmap <- tm_shape(cuencasUTM) +
  tm_fill(
    fill = "MediaLimo",
    fill.scale = tm_scale_continuous(),
    fill.legend = tm_legend(
      title = 'Media Limo',
      text.size = 20,
      title.size = 23,
      legend.outside = TRUE,
      frame = "gray50"
    )
  ) +
  tm_borders()
cuencas_tmap

muestreo_tmap <- tm_shape(muestreo) +
  tm_dots("Limo", size = 0.5,
          palette = "BuGn", colorNA= NULL,
          legend.hist=T) +
  tm_layout(legend.format = list(text.separator= " a "),
            legend.outside = TRUE,
            legend.hist.width = 2.5)
muestreo_tmap

tm_shape(cuencasUTM) +
  tm_fill("MediaLimo", 
          style = "cont", 
          # palette = c("red", "blue"),
          textNA = "Sin Datos",
          title.size = "Media Limo") +
  tm_borders() +
  tm_legend(
    text.size=1,
    title.size=1.2,
    legend.outside=TRUE,
    frame="gray50",
    height=.6) +
  tm_shape(muestreo) +
  tm_dots("Limo", size = 0.5,
          palette = "BuGn", colorNA= NULL,
          legend.hist=T) +
  tm_layout(legend.format = list(text.separator= " a "),
            legend.outside = TRUE,
            legend.hist.width = 2.5)

cuencas_tmap +
muestreo_tmap
cuencas_tmap +
muestreo_tmap +
  tm_scale_bar() +
  tm_compass(position = c( "right", "top"))

tmap_cuencas <- tm_shape(cuencasUTM) +
  tm_fill("MediaLimo", style = "quantile") +
  tm_borders() +
  tm_legend(legend.outside = TRUE)
tmap_cuencas

tmap_muestreo <-   tm_shape(muestreo) +
  tm_bubbles(col = "K", style = "cont", textNA = "Sin dato") +
  tm_legend(legend.outside = TRUE)
tmap_muestreo

tmap_arrange(tmap_cuencas, tmap_muestreo)
# tmap_mode("view")
tm_shape(cuencasUTM) +
  tm_fill("MediaLimo",
          fill.scale = tm_scale_continuous(values = "RdYlGn"),
          fill.legend = tm_legend(title = "Media Limo")) +
  tm_borders() +
  tm_facets("SISTEMA", nrow = 1, sync = TRUE) +
  tm_basemap("OpenStreetMap")

Referencias

Bivand, Roger, y Albrecht Gebhardt. 2000. «Implementing Functions for Spatial Statistical Analysis Using the Language». Journal of Geographical Systems 2 (3): 307-17.
Pebesma, Edzer. 2018. «Simple Features for R: Standardized Support for Spatial Vector Data». The R Journal 10 (1): 439-46. https://journal.r-project.org/archive/2018/RJ-2018-009/index.html.