library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.1
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.6.1
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(readxl)
## Warning: package 'readxl' was built under R version 3.6.1
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.2
## -- Attaching packages -------------------------------------------------------------- tidyverse 1.3.0 --
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 1.0.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## v purrr 0.3.3
## Warning: package 'tibble' was built under R version 3.6.1
## Warning: package 'tidyr' was built under R version 3.6.1
## Warning: package 'readr' was built under R version 3.6.1
## Warning: package 'purrr' was built under R version 3.6.1
## Warning: package 'dplyr' was built under R version 3.6.1
## Warning: package 'stringr' was built under R version 3.6.1
## Warning: package 'forcats' was built under R version 3.6.1
## -- Conflicts ----------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sp)
## Warning: package 'sp' was built under R version 3.6.1
library(maptools)
## Warning: package 'maptools' was built under R version 3.6.1
## Checking rgeos availability: TRUE
X2007sep <- read_excel("2007sep.xlsx")
View(X2007sep)
Huatabampo <- (X2007sep)
##Datos disponibles de pozos
library(DT)
## Warning: package 'DT' was built under R version 3.6.1
datatable(X2007sep)
str(Huatabampo)
## Classes 'tbl_df', 'tbl' and 'data.frame': 293 obs. of 10 variables:
## $ MODULO: num 1 1 1 1 1 1 1 1 1 1 ...
## $ POZO : chr "1" "2" "3" "4" ...
## $ X : num 620903 620915 620943 620879 620888 ...
## $ Y : num 2962392 2963671 2964903 2965667 2966604 ...
## $ SNM : num 3.91 4.53 2.8 3.64 3.49 ...
## $ NF : num 2.68 2.61 1.3 2.14 2.01 2 1.63 2.82 3 3 ...
## $ CE : num 2.83 8.35 8.66 8.34 9.18 7.9 9.64 7.17 1.88 1.93 ...
## $ PPM : num 1811 5344 5542 5338 5875 ...
## $ PH : num 6.8 6.9 6.8 7.1 6.6 6.8 6.5 6.9 7 7 ...
## $ TEMP : num 28.5 29.2 28.9 29.4 28.3 28.4 28 27.5 28.7 28.6 ...
PPM <- Huatabampo$PPM
PH <- Huatabampo$PH
NF <- Huatabampo$NF
SNM <- Huatabampo$SNM
datos <- data.frame(PPM, PH, NF, SNM)
#Primer gr攼㸱fico de correlaci昼㸳n
pairs(datos)

cor(NF, SNM, method = c("pearson", "kendall", "spearman"))
## [1] 0.67311
cor.test(NF, SNM, method=c("pearson", "kendall", "spearman"))
##
## Pearson's product-moment correlation
##
## data: NF and SNM
## t = 15.526, df = 291, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6052017 0.7312929
## sample estimates:
## cor
## 0.67311
ggplot(Huatabampo, aes(x = SNM, y = NF)) +
geom_point()

cor(SNM, NF, method = c("pearson", "kendall", "spearman"))
## [1] 0.67311
cor.test(SNM, NF, method=c("pearson", "kendall", "spearman"))
##
## Pearson's product-moment correlation
##
## data: SNM and NF
## t = 15.526, df = 291, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6052017 0.7312929
## sample estimates:
## cor
## 0.67311
cor.test(PPM, PH, method=c("pearson", "kendall", "spearman"))
##
## Pearson's product-moment correlation
##
## data: PPM and PH
## t = -11.07, df = 291, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.6202473 -0.4583503
## sample estimates:
## cor
## -0.544348
# Boxplot of SNM VS NF
# Boxplot of weight vs. weeks
ggplot(data = Huatabampo,
aes(x = cut(SNM, breaks = 4), y = NF)) +
geom_boxplot()

ggplot(data = Huatabampo,
aes(x = cut(SNM, breaks = 4), y = PPM)) +
geom_boxplot()

library(plotly)
## Warning: package 'plotly' was built under R version 3.6.1
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggmap':
##
## wind
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
Huat <- ggplot(Huatabampo, aes(x = NF, y = PPM, color = factor(MODULO))) +
geom_point()
ggplotly(Huat)
library(dplyr)
library(tidyr)
library(ggplot2)
library(broom)
## Warning: package 'broom' was built under R version 3.6.1
library(dplyr)
Huatabampo %>%
filter(NF <=2.9 ) %>%
ggplot(aes(x = NF, y = SNM)) +
geom_point()

# Compute correlation
Huatabampo %>%
summarize(N = n(), r = cor(SNM, NF))
## # A tibble: 1 x 2
## N r
## <int> <dbl>
## 1 293 0.673
#Para hacer el mapa
library(sf)
## Warning: package 'sf' was built under R version 3.6.1
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(rgdal)
## Warning: package 'rgdal' was built under R version 3.6.1
## rgdal: version: 1.4-4, (SVN revision 833)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
## Path to GDAL shared files: C:/Users/Samsung/Documents/R/win-library/3.6/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
## Path to PROJ.4 shared files: C:/Users/Samsung/Documents/R/win-library/3.6/rgdal/proj
## Linking to sp version: 1.3-1
library(gstat)
## Warning: package 'gstat' was built under R version 3.6.1
## Registered S3 method overwritten by 'xts':
## method from
## as.zoo.xts zoo
library(RSAGA)
## Warning: package 'RSAGA' was built under R version 3.6.1
## Loading required package: shapefiles
## Warning: package 'shapefiles' was built under R version 3.6.1
## Loading required package: foreign
##
## Attaching package: 'shapefiles'
## The following objects are masked from 'package:foreign':
##
## read.dbf, write.dbf
## Loading required package: plyr
## Warning: package 'plyr' was built under R version 3.6.1
## -------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## -------------------------------------------------------------------------
##
## Attaching package: 'plyr'
## The following objects are masked from 'package:plotly':
##
## arrange, mutate, rename, summarise
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following object is masked from 'package:purrr':
##
## compact
library(raster)
## Warning: package 'raster' was built under R version 3.6.1
##
## Attaching package: 'raster'
## The following object is masked from 'package:plotly':
##
## select
## The following object is masked from 'package:dplyr':
##
## select
## The following object is masked from 'package:tidyr':
##
## extract
pozos <- st_read("2017HuataBampo.shp")
## Reading layer `2017HuataBampo' from data source `C:\Users\Samsung\Documents\Huatabampo\2017HuataBampo.shp' using driver `ESRI Shapefile'
## Simple feature collection with 293 features and 10 fields
## geometry type: POINT
## dimension: XY
## bbox: xmin: 620553 ymin: 2956532 xmax: 642471 ymax: 2975407
## epsg (SRID): 32612
## proj4string: +proj=utm +zone=12 +datum=WGS84 +units=m +no_defs
ggplot(pozos) +
geom_sf()

mapview::mapview(pozos,labels=F)
#Grafico interactivo
ggplotly(Huat)
#Datos de vegetacion
#Esto muestra el 攼㸱rea cultivada en huatabampo
#obtenido de una imagen landast 8
vegetacion <- st_read("vegetation.shp")
## Reading layer `vegetation' from data source `C:\Users\Samsung\Documents\Huatabampo\vegetation.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1623 features and 3 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 620565 ymin: 2956545 xmax: 642465 ymax: 2975385
## epsg (SRID): 32612
## proj4string: +proj=utm +zone=12 +datum=WGS84 +units=m +no_defs
ggplot(vegetacion) +
geom_sf()

mapview::mapview(vegetacion,labels=F, color = "seagreen3", alpha.regions =0.3)