# install.packages("raster")
# install.packages("sp")
# install.packages("rgdal")
library(raster)
## Loading required package: sp
library(sp)
library(rgdal)
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/STEVEN/Documents/R/win-library/4.1/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/STEVEN/Documents/R/win-library/4.1/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/STEVEN/Documents/R/win-library/4.1/rgdal/proj
# "llamar mis imagenes"
b2 <-raster("C:/Users/STEVEN/Google Drive/Universidad/10 Semestre/Geomatica - Electiva II/P02/LC08_L1TP_008058_20210901_20210909_02_T1_B2.tif")
b3 <-raster("C:/Users/STEVEN/Google Drive/Universidad/10 Semestre/Geomatica - Electiva II/P02/LC08_L1TP_008058_20210901_20210909_02_T1_B3.tif")
b4 <-raster("C:/Users/STEVEN/Google Drive/Universidad/10 Semestre/Geomatica - Electiva II/P02/LC08_L1TP_008058_20210901_20210909_02_T1_B4.tif")
b5 <-raster("C:/Users/STEVEN/Google Drive/Universidad/10 Semestre/Geomatica - Electiva II/P02/LC08_L1TP_008058_20210901_20210909_02_T1_B5.tif")
s<--stack(b5,b4,b3)
s
## class      : RasterBrick 
## dimensions : 7741, 7581, 58684521, 3  (nrow, ncol, ncell, nlayers)
## resolution : 30, 30  (x, y)
## extent     : 411585, 639015, 203385, 435615  (xmin, xmax, ymin, ymax)
## crs        : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs 
## source     : r_tmp_2021-09-14_212113_11912_41783.grd 
## names      : LC08_L1TP_008058_20210901_20210909_02_T1_B5, LC08_L1TP_008058_20210901_20210909_02_T1_B4, LC08_L1TP_008058_20210901_20210909_02_T1_B3 
## min values :                                      -65535,                                      -65535,                                      -65535 
## max values :                                       -5682,                                       -6075,                                       -7025
par(mfrow = c(2,2))
plot (b2,main = "blue", col = gray(0:100 /100))
plot (b3,main = "gren", col = gray(0:100 /100))
plot (b4,main = "red", col = gray(0:100 /100))
plot (b5,main = "infrared", col = gray(0:100 /100))

# Stack o combinacion a color verdadero
landstaRGB <--stack(b4,b3,b2)
plotRGB(landstaRGB, axes = TRUE, stretch = "lin", main = "landsat color verdadero")